Thursday, April 16, 2015

Opening Form Using X++ Code in AX

There are different methods to open the form using code, follow the below methods.


Method 1:-

You can open a form with the help of single line of code.

Follow the below code to open the form :

new MenuFunction(MenuItemDisplayStr(CustTable),MenuItemType::Display).run();

The above code will open the CustTable form.

Method 2:-

If you want to open the form by passing some arguments, follow the below code

static void FormopenthroughCode()
{
   Args args = new Args();
   ;
   args.record(CustTable::find('CUS-0002'));
   new MenuFunction(MenuItemDisplayStr(CustTable),MenuItemType::Display).run(Args);
}


It will open the CustTable form and filter out the customer with account number CUS-0002.


--------------------------------------------------------------------------------------------------------------------

You can also try below method to open the form by passing an argument.
Below code will also help you to implement parent-child form functionality
For example :- If you want Parent Form to be open until Child Form is closed.

static void OpenForm ()

     FormRun formRun;
     Args args = new Args();
     ;
     args.name(formstr(CustTable));
     args.caller(element);

     formRun = ClassFactory.formRunClass(args);
     formRun.init();
     formRun.run();
     formRun.wait(); //form will wait until you close the child form.
     formRun.detach();//this will add the close button
}

No comments:

Post a Comment

How to enable the dimension fields based on the Item selected on the form.

[Form] public class KMTShipFromWarehouses extends FormRun {     InventDimCtrl_Frm_EditDimensions        inventDimFormSetup;     /// &l...