How to open form using different way in dynamics ax

Description:-

A short tutorial on how to open a form in Dynamics Ax (Axapta) by code. 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.

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

Method 2:-

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

static void openFormCode()
{
   Args args = new Args();
   ;
   args.record(CustTable::find('CUS_1000'));
   new MenuFunction(MenuItemDisplayStr(CustTable),MenuItemType::Display).run(Args);
}

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


Method 3:-

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
}

Method 4:-

You can also try below method to open the form by passing an argument.

static void FormOpenCodeNew()
{ 
    Args args = new Args();
    FormRun formrun;    
    super(); 
    //Pass parametres to form
    args.record(cTable);
    args.parm(cTable.AccountNum); 
    args.name(formstr(MyForm));
    formRun = classFactory.formRunClass(Args);
    formRun.init();
    formrun.run(); 
    // This waits until the form closes
    if (!formRun.closed())
        formrun.wait(true); 
}

Related Posts

Previous
Next Post »

Thanks for comments.....