How to invoke a menu item from code in AX 2012

50,238

Solution 1

Set the AutoDeclaration of the Register button to Yes.

Then it is straightforward to call clicked:

 register.clicked(); 

It is not advisable to have large bodies of code in form methods.

Reference:

The basic concept of three-tier architecture is that forms should be used only for the presentation tier and hence no other code such as business logic should be there on forms. The code placed on forms also reduces their reusability and the ease of further customization; e.g. if you want to develop an enterprise portal, the code written on forms will have to be written again in classes or table methods, etc., which will make the implementation complex.

Solution 2

I see that you're actually trying to execute the clicked() method, but if you want to execute a Menu Item through code, you can do the following:

new MenuFunction(menuItemDisplayStr(MyDisplayMenuItem), MenuItemType::Display).run();

Of course the code above may be changed to execute different kinds of Menu Items, for example, the code below runs an Output Menu Item:

new MenuFunction(menuItemOutputStr(MyOutputMenuItem), MenuItemType::Output).run();

And if you need any argument on the Menu Item you're trying to execute, you can pass it with the Args class:

Args args = new Args();

args.record(myArgumentRecord);

args.caller(this);

new MenuFunction(menuItemOutputStr(MyOutputMenuItem), MenuItemType::Output).run(args);
Share:
50,238
alphaprolix
Author by

alphaprolix

Senior Software Engineer Expertise: Microsoft Dynamics AX 2012 Microsoft SQL Server Microsoft .Net Framework Microsoft C# Website

Updated on July 30, 2020

Comments

  • alphaprolix
    alphaprolix almost 4 years

    I have some custom code in PurchTable "Register" menuitem's clicked method, Now I need to run the Register command from code after a buttons function has been perfomed.

    My question is that how can I call the Register command from code ?

    Screenshot