Custom lookup for Dialog fields - easy way

Hi,


SysTableLookup can be used in dialogs to create custom lookups.

control.registerOverrideMethod can be used to register the methods to override by an object
Here is the example which shows basic usage of both. We will create a dialog and get a lookup of account numbers on a control

protected Object dialog()
{
    FormStringControl control;
    ;

    dialog = super();
    dialogFeildAccountNum = dialog.addField(extendedTypeStr(AccountNum));
    control = dialogFeildAccountNum.control();
    control.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(DialogLookup, accountNumLookup), this);
   
    return dialog;
}

Here is the method:
private void accountNumLookup(FormStringControl _control)
{
    SysTableLookup          sysTableLookup;
    QueryBuildDataSource    queryBuildDataSource;
    Query                   query = new Query();

    queryBuildDataSource = query.addDataSource(tablenum(CustTable));

    sysTableLookup = SysTableLookup::newParameters(tablenum(CustTable), _control);
    sysTableLookup.addLookupfield(fieldnum(CustTable, AccountNum),  true);
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}

Note:
Class - RunOn property must be other than Server.
I got the below error when I tried with RunOn Property  = server

"The method DialogControl.control cannot be called from the server; use methods on the DialogField class instead."

Comments

Popular posts from this blog

x++ code to Generate cheque for vendor payment journal

Import Procurement Hierarchy / Categories with out code in ax 2012

Copy favorites From one user to another user - Ax 2012