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

How to dynamically add event handlers to D365 menu items

(0) ShareShare
ReportReport
Posted on by 20
Hi, I'm new to D365 fin ops. I've managed to create a new form based on the Simple List and I'm currently trying to customise the Action Pane.
 
I am dynamically creating the menu items based on the contents of some tables, namely ClimateControlType and ClimateControlOption.
 
My problem now is how to handle the OnClicked event of the menu items in code.
 
This is what I have but I'm not sure how to progress from here:
 
    public void init()
    {
        super();
        FormButtonGroupControl btnGroup = FormActionPaneControl.addControl(FormControlType::ButtonGroup, 'ButtonGroup');
        FormMenuButtonControl btnSetAll = btnGroup.addControl(FormControlType::MenuButton, 'btnSetAll');
        btnSetAll.text('Set all');
        ClimateControlOption climateOptions;
        while select climateOptions
        {
            FormButtonControl btn = btnSetAll.addControl(FormControlType::Button, 'btnSetAll'+climateOptions.ClimateControlOptionCode);
            btn.text(climateOptions.ClimateControlOptionDescription);
            btn.OnClicked = SetAllClick;
        }
        ClimateControlType climateTypes;
        while select climateTypes
        {
            FormMenuButtonControl btnSetAllType = btnGroup.addControl(FormControlType::MenuButton, 'btnSetAllType'+climateTypes.ClimateControlTypeCode);
            btnSetAllType.text('Set all '+climateTypes.ClimateControlTypeDescription);
            while select climateOptions
            {
                FormButtonControl btn = btnSetAllType.addControl(FormControlType::Button, 'btnSetAllType'+climateTypes.ClimateControlTypeCode+climateOptions.ClimateControlOptionCode);
                btn.text(climateOptions.ClimateControlOptionDescription);
            }
        }
    }
    public void SetAllClick(FormControl sender, FormControlEventArgs e)
    {
    }
I have the same question (0)
  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at
    What exactly are you struggling with regarding "how to handle the OnClicked event"?
  • Community member Profile Picture
    20 on at
    This line won't compile and it doesn't seem to recognise the SetAllClick method declared below.
     
    btn.OnClicked = SetAllClick;
     
    I want all the generated menu items to call this method because the code will be very similar.
  • Verified answer
    Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at
    That's a wrong syntax indeed. The correct syntax is
     
    btn.OnClicked += eventHandler(...)
     
    where the parameter may be either instance method (myInstance.myMethod) or a static method (MyType::myMethod).
  • Community member Profile Picture
    20 on at
    Thanks Martin,  is there anyway to specify the current instance like this::myMethod?
  • Community member Profile Picture
    20 on at
    I think I've figured it out.  I was using the double colon rather than a period.
  • Community member Profile Picture
    20 on at
    I'm trying to mark your replay as the answer Martin but the forum just seems to hang with the busy indicator when I do it.

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
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans