Wednesday, February 5, 2014

Different ways of Opening a Form from Code in AX

Hi Guys..

Below are few ways to call a Form in AX using X++ code.....

Calling a form Using Menuitem.
Args args = new Args();
args.record(myArgumentRecord);
args.caller(this);
new MenuFunction(menuItemOutputStr(MyDisplayMenuItem), MenuItemType::Display).run(args);
Calling Form Using FormRun.
static void OpenFormByCodeB()
{
FormRun formRun;
Args args = new Args();
;
args.name(formstr(CustTable));
args.record(CustTable::find('ABC'));
formRun = ClassFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.wait();
}
if we change the type of formRun from class FormRun to class Object, we can implement and execute extra methods on our destination form.This helps us to call extra customizations .

static void OpenFormByCodeB()
{
Object formRun;
Args args = new Args();
;
args.name(formstr(CustTable));
args.record(CustTable::find('ABC'));
formRun = ClassFactory.formRunClass(args);
formRun.init();
formRun.callyourmethodhere();
formRun.run();
formRun.wait();
}
we can also pass records as parameters in the above code...
static void CallLedgerBudgetForm(Args _args)
{
    LedgerTable                             ledgerTable;
    BudgetModelId                           modelId;
    Args                                    args;
    FormRun                                 formRun;
    FormDataSource                          fds;
    QueryBuildDataSource                    qbds;
    QueryBuildRange                         qbr;
    ;
    select LedgerTable where LedgerTable.AccountNum == '110110' ;
    ModelId= 'SUb1';
    args = new Args(formstr("LedgerBudget"));
    args.record(LedgerTable);
    formRun = classfactory.formRunClass(args);
    formRun.init();
    fds = formRun.dataSource();
    qbds = fds.query().dataSourceTable(tablenum(LedgerBudget));
    qbr = qbds.addRange(fieldnum(LedgerBudget,ModelNum));
    qbr.value(queryvalue(modelId));
    qbr.status(RangeStatus::Hidden);
    formRun.run();
    formRun.wait();
}

Hope this helps you guys.......






No comments:

Post a Comment