Saturday, June 6, 2020

Creating custom lookup in dialog form in Ax 2012

1. write following in class declaration

MainAccount                             mainAccount;





2. Write a new method "accountLookup"

public void accountLookup(FormStringControl _control2)
{
    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    SysTableLookup          sysTableLookup = SysTableLookup::newParameters(tableNum(mainAccount),_control2);

    sysTableLookup.addLookupField(fieldNum(mainAccount, mainaccountid));
    sysTableLookup.addLookupField(fieldNum(mainAccount, Name));

    queryBuildDataSource = query.addDataSource(tableNum(mainAccount));

    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}







3. now go to "dialog" method and after taking the input for account write the following code

    dialog.addTabPage("Account");
    dialog.addGroup("Account Parameters").columns(2);
    dlgMainAccounts         = dialog.addFieldValue(extendedTypeStr(String255),mainAccounts,"Accounts");
    control2 = dlgMainAccounts.control();
    control2.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(TTC_EOM,accountLookup), this);
    dlgMainAccounts.mcrReplaceOnLookup(false); //this is for entering multiple account values in the field
    controlMainAccounts    = dlgMainAccounts.control();