web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

my override button clicked() not active my code

(0) ShareShare
ReportReport
Posted on by 2,050

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

I have the same question (0)
  • Verified answer
    ergun sahin Profile Picture
    8,826 Moderator on at

    Add args

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

  • Suggested answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    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?

  • mohammed.mqi Profile Picture
    2,050 on at

    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
    101,162 Moderator on at

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

  • mohammed.mqi Profile Picture
    2,050 on at

    i think my code not hit 

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

    pastedimage1639652461372v1.png

  • Verified answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    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
    2,050 on at

    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);
            }
    
    
    
        }
    
    }

  • nmaenpaa Profile Picture
    101,162 Moderator on at

    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 456 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans