Form open through X++ code / Go to main table form
Hello guys J let me cover a very short topic on how to open a form in
MS Dynamics Ax by code.
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();
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);
}
This code will open the CustTable form and filter out the customer with accountnumber CUS-0001.
Use the args methods like parm and parmEnum to provide your target form with more data.
Also there are other ways by which we can open form through code:
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);
}
Thus, by writing the above code
in Jumpref method allows you to go to its master form.
Keep reading!! J

Thanks for giving valuable explanation
ReplyDeleteThanks murali..Keep visiting for more threads...:)
DeleteReally useful walkthrough. Opening forms programmatically in AX is one of those areas where the concepts feel simple on the surface but end up being powerful once you understand the flexibility behind Args, MenuFunction, and FormRun. Your examples clearly show how easy it is to start with a direct form launch and then evolve into passing records, parameters, or even tailoring the experience with a custom JumpRef.
ReplyDeleteThe reminder about Args.record() is particularly helpful. Many developers underestimate how cleanly AX handles context when you supply the correct table buffer. It saves a lot of work compared to manually setting form controls or constructing ranges. The FormRun example also highlights what is happening under the hood which can be valuable when debugging or extending behavior.
JumpRef implementations remain a key part of creating intuitive navigation. A user should always feel like the system understands what they are working with and can take them straight to the relevant master data. Your sample patterns are the ones every AX developer should keep handy.
For teams managing enhancements like these across modules, a structured approach to testing is important so that navigation flows remain reliable as code evolves. Using something like Tuskr test management software makes it easier to track scenarios and ensure form interactions function the way users expect.