Wednesday, August 17, 2016

How to create Lookups on Dialog: SysTableLookup and registerOverrideMethod

We can create a lookup in dialog without hardcode the field object (Fld1_1_lookup) using the form control's registerOverride method.

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();
dialogFieldAccountNum = dialog.addField(extendedTypeStr(AccountNum));
// set control
control = dialogFieldAccountNum.control();
control.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(MyClass, custTableLookup), this);

dialogName = dialog.addField(extendedTypeStr(Name));

return dialog;
}

//Here is the lookup method:
private void custTableLookup(FormStringControl _control)
{
SysTableLookup sysTableLookup;
QueryBuildDataSource queryBuildDataSource;
Query query = new Query();
QueryBuildRange qbr;

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

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

if( dialogName.value() || name ) // name is a variable
{
qbr = SysQuery::findOrCreateRange(queryBuildDataSource, fieldNum(CustTable, Name));
//qbr.value(queryValue(dialogName.value())); // can use dialogField also, depend on the situation
qbr.value(queryValue(name));
}

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

No comments:

Post a Comment