How to call a method from a button created in runtime?

I need to call a report by clicking a menuitembutton which is created in runtime.

Can anyone teach me how I can achieve this? I’m using AX 2009.

Many Thanks,

Is this menuItemButton created at RunTime?? If YES - Call this method in the init method of form: element.controlMethodOverload(true);

and Create new method with the control name as Prefix to call the clicked method for the button:

void ControlName_clicked()


new menufunction(menuitemdisplaystr(“reportObject”), menuitemtype::output);


To call a report’s menu item , use this one :

menu Function menu Function;
menu Function = new menu Function(reportStr(Cust), MenuItemType::Output);

if you need to call a report when clicking on a button

void clicked()
Args args = new args();
ReportRun reportRun;
reportRun = classFactory.reportRunClass(args);




If it’s a menu item, the target of the menu item will be called automatically on click. What else do you need?

Dear All,

Thanks for the replies!

Vishal, I used some codes suggested by you in method “public void init()”

FormButtonControl _button;



_button = menuButton.addControl(FormControlType::Button, #button);


_button.helpText(“help text here”);


This part is OK, I can created the button in runtime, thank you!

Also, I used the codes from Nagaraj, method “void button_Clicked()” was created in form Methods node.

However, error message “Variable Args has not been declared.” was returned once I saved the code.

Any suggestion?