Dynamics AX 2012 Tips And Tricks : Calling MenuItem through Code in Dynamics AX 2012
14 Mar 2014
Calling MenuItem through Code in Dynamics AX 2012 Tips and Tricks
We often need to execute menu items from X+. Menu Items are represented by the MenuFunction class. Below is a code sample that depicts how to run Menu Items through code.
MenuFunction menuFunction = new MenuFunction(menuitemdisplaystr(MENUITEM), MenuItemType::Display);
Args args = new Args();
args.caller(element);
args.record(DS);
menuFunction.run(args);
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:
MenuFunction menuFunction;
menuFunction = new MenuFunction(menuItemOutputStr(MENUITEM), MenuItemType::Output);
menuFunction.run();
You should always use functions to get the name of the menu item instead of using a hardcoded string. This insures that in the event that somebody changes the name of the menu item, your code stops compiling and you can fix it.
Below are three functions that are most commonly used to get the Menu Items’ name. Their names are pretty straightforward:
menuItemActionStr
menuItemDisplayStr
menuItemOutputStr
ABOUT Folio3 Dynamics Services
As Dynamics AX experts we specialize in Dynamics AX development including Dynamics AX customization, integration, implementation and mobility solutions. If you have a Dynamics AX development requirement you would like to discuss or would like to know more about our Dynamics AX development services, please get in touch with us.