Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to invoke a menu item from code in AX 2012

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

like image 913
alphaprolix Avatar asked Nov 28 '22 17:11

alphaprolix


2 Answers

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);
like image 181
Smur Avatar answered Jan 20 '23 09:01

Smur


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.

like image 28
Jan B. Kjeldsen Avatar answered Jan 20 '23 08:01

Jan B. Kjeldsen