Skip to main content

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);

(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




Comments

  1. Thanks for giving valuable explanation

    ReplyDelete
    Replies
    1. Thanks murali..Keep visiting for more threads...:)

      Delete

Post a Comment