Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / my override button cli...
Finance forum
Answered

my override button clicked() not active my code

Posted on by 2,016

Greeting everyone

I've created a new button
and i override button clicked() on my extension form

because i want add condition before user clicked on post button

pastedimage1639647933345v1.png

so then i override a clicked method of a button

to my class

pastedimage1639648003057v2.png

class MycustomPriceDiscAdm_Form_Handler
{
    
    /// 
    ///
    /// 
    /// 
    /// 
    [FormControlEventHandler(formControlStr(PriceDiscAdm, NewPostButton), FormControlEventType::Clicked)]
    public static void NewPostButton_OnClicked(FormControl sender, FormControlEventArgs e)
    {
        PriceDiscAdmTrans   priceDiscAdmTrans;
        FormRun             formRun=sender.formRun() as formRun;
        FormDataSource      priceDiscAdmTrans_ds;

        priceDiscAdmTrans_ds=sender.formRun().dataSource(1);
        priceDiscAdmTrans=priceDiscAdmTrans_ds.cursor();

        MenuFunction menuFunction;

        menuFunction = new MenuFunction(menuItemActionStr(PriceDiscAdmPost), MenuItemType::Action);

        menuFunction.run();


    }

}

but i got this error when i clicked on my button 

(Called without valid buffer.)

pastedimage1639648206304v3.png

  • nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: my override button clicked() not active my code

    No, event handlers and _Extension classes are completely separate things, you should not mix them.

    I think it's best to wait for your inputs from the debugging results before proceeding any further.

  • mohammed.mqi Profile Picture
    mohammed.mqi 2,016 on at
    RE: my override button clicked() not active my code

    should I indicate that as extension

    like add this above my code?

    [ExtensionOf(formControlStr(PriceDiscAdm,NewPostButton))

    class MycustomPriceDiscAdm_Form_Handler
    {
        
        /// 
        ///
        /// 
        /// 
        /// 
        [FormControlEventHandler(formControlStr(PriceDiscAdm, NewPostButton), FormControlEventType::Clicked)]
        public static void NewPostButton_OnClicked(FormControl sender, FormControlEventArgs e)
        {
            PriceDiscAdmTrans   priceDiscAdmTrans;
            FormRun             formRun=sender.formRun() as formRun;
            FormDataSource      priceDiscAdmTrans_ds;
            Args            args = new Args();
            MenuFunction menuFunction;
            SystemNotificationDataContract notification = new SystemNotificationDataContract();
            
            args.record(priceDiscAdmTrans);
    
            priceDiscAdmTrans_ds=sender.formRun().dataSource(1);
            priceDiscAdmTrans=priceDiscAdmTrans_ds.cursor();
    
            menuFunction = new MenuFunction(menuitemActionStr(PriceDiscAdmPost), MenuItemType::Action);
    
            if (menuFunction && menuFunction.checkAccessRights())
            {
                menuFunction.run(args);
            }
    
    
    
        }
    
    }

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: my override button clicked() not active my code

    Your code is clearly executed because you get the error messages. And you even get a different error message now, than before changing your code.  You don't see event handlers in the form designer in Visual Studio. Just debug your code and you will find what's wrong. If you need any more help, please share all the details that you learned while debugging.  If you need help in learning how to debug, please search the web - you'll find all the information that you need.

    However, I don't understand why you simply didn't add a MenuItemButton, pointing to PriceDiscAdmPost menu item. You don't need any code to call menu items from forms..

  • mohammed.mqi Profile Picture
    mohammed.mqi 2,016 on at
    RE: my override button clicked() not active my code

    i think my code not hit 

    i'm not sure because i didn't see method clicked on button

    pastedimage1639652461372v1.png

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: my override button clicked() not active my code

    Did you so far debug your code? You should be able to catch these issues by debugging.

  • mohammed.mqi Profile Picture
    mohammed.mqi 2,016 on at
    RE: my override button clicked() not active my code

    thanks all for replay i still getting this error 

    No lines exist in the journal.

    pastedimage1639650426898v1.png

    here my code

    pastedimage1639651051121v2.png

    class MycustomPriceDiscAdm_Form_Handler
    {
        
        /// 
        ///
        /// 
        /// 
        /// 
        [FormControlEventHandler(formControlStr(PriceDiscAdm, NewPostButton), FormControlEventType::Clicked)]
        public static void NewPostButton_OnClicked(FormControl sender, FormControlEventArgs e)
        {
            PriceDiscAdmTrans   priceDiscAdmTrans;
            FormRun             formRun=sender.formRun() as formRun;
            FormDataSource      priceDiscAdmTrans_ds;
            Args            args = new Args();
            MenuFunction menuFunction;
            args.record(priceDiscAdmTrans);
    
            priceDiscAdmTrans_ds=sender.formRun().dataSource(1);
            priceDiscAdmTrans=priceDiscAdmTrans_ds.cursor();
    
            menuFunction = new MenuFunction(menuitemActionStr(PriceDiscAdmPost), MenuItemType::Action);
    
            if (menuFunction && menuFunction.checkAccessRights())
            {
                menuFunction.run(args);
            }
    
    
    
        }
    
    }

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: my override button clicked() not active my code

    Hi mohammed,

    you seem to be calling menu item PriceDiscAdmPost without providing any buffer with args. That's why you get the error.

    Perhaps you would like to send priceDiscAdmTrans buffer but you forgot to add such code?

  • Verified answer
    ergun sahin Profile Picture
    ergun sahin 8,812 Super User on at
    RE: my override button clicked() not active my code

    Add args

    Args            args = new Args();
    args.record(priceDiscAdmTrans);
    
    menuFunction = new MenuFunction(menuitemActionStr(PriceDiscAdmPost), MenuItemType::Action);
    
    if (menuFunction && menuFunction.checkAccessRights())
    {
        menuFunction.run(args);
    }

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,513 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,862 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans