Monday, May 2, 2022

How to call menu item through code in D365 FO

Below code will call Action menu item. Args is used to send parameter to class

MenuFunction menuFunction;

args.record(dmfExecution); // to send whole table as parameter

args.caller(this);

menuFunction = new MenuFunction(menuitemActionStr(DMFStagingWriterBatch), MenuItemType::Action);

menuFunction.run(args);



Below code will call Action menu item. Args is used to send parameter to class

Args args = new Args();

args.record(VendTable::find("XYZ")); // to send specific record in a table

MenuFunction menuFunction;

menuFunction = new MenuFunction(menuItemDisplayStr(MyDisplayMenuItem), MenuItemType::Display);

menuFunction.run();


Use formRun to call the form.

FormRun formRun;

Args args = new Args();

;

args.name(formstr(VendTable));

args.record(CustTable::find("XYZ"));

formRun = ClassFactory.formRunClass(args);

formRun.init();

formRun.run();

formRun.wait();


Below code will call the Output menu item.

MenuFunction menuFunction; 

menuFunction = new MenuFunction(menuItemOutputStr(MyOutputMenuItem), MenuItemType::Output);

menuFunction.run();