Monday, November 26, 2012

Lookups on Dialog: SysTableLookup and registerOverrideMethod

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();
}

6 comments:

  1. Nicely explained. I have shared this link on my blog as well.

    http://axrachit.blogspot.com.au/2013/09/ax2012-custom-lookup-on-dialog-control.html

    ReplyDelete
  2. Thanks for the tutorial. However i keep getting this error :
    Error executing code: FormStringControl (object), method Lookup called with invalid parameters.

    ReplyDelete
    Replies
    1. I had the same issue, and like many annoying things with annoying AX, all that was required was a restart of my development environment. Now I hit my breakpoint in the new target method without issue.

      Delete
  3. Hi,
    what is DialogLookup, class?

    ReplyDelete
  4. great it works! you saved the day :D

    ReplyDelete