Sometimes it is very essential
to open a form (or) intermediate form through code in AX. Or when we implement
the functionality of “Go to main table”, we can use X++ code to open the form.
In the direct example, all it takes is one line of code.
new
MenuFunction(MenuItemDisplayStr(CustTable),MenuItemType::Display).run();
Note:-
In this code at the place of "Form MenuItem Name" you need to create a menuitem of your form and paste that name at this place.
The above code will open the CustTable form. This is as simple as it looks.
Now if we want to supply some arguments to the opening form, this is also possible with the optional args parameter.
Let us observe this with quick example:
static void FormopenthroughCode()
{ Args args = new Args();
;
args.record(CustTable::find('CUS-0001'));
new MenuFunction(MenuItemDisplayStr(CustTable),MenuItemType::Display).run(Args);
}
Use the args methods like parm and parmEnum to provide your target form with more data.
This next example gives the same result as the previous one.
static void OpenForm ()
{ FormRun formRun;
Args args = new Args();
;
args.name(formstr(CustTable));
args.record(CustTable::find(' CUS-0001'));
formRun = ClassFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.wait();
}
Also, when you want to assign “Go
to main table form” for any string you can directly override the ‘JumpRef’
method and simply write the code in it as:
Args args = new Args();
;
args.record(CustTable::find('CUS-0001'));
new MenuFunction(MenuItemDisplayStr(CustTable),MenuItemType::Display).run(Args);
;
args.record(CustTable::find('CUS-0001'));
new MenuFunction(MenuItemDisplayStr(CustTable),MenuItemType::Display).run(Args);
(or)
SalesTable sales;
Select firstonly sales
where sales.SalesId == SpecTransDetails.JournalNum; //
your range from form
if (sales)
{
args.record(salestable::find(SpecTransDetails.JournalNum));
new
MenuFunction(MenuItemDisplayStr(SalesTable),MenuItemType::Display).run(Args);
}
No comments:
Post a Comment