Custom Lookup for a dialog field

By

This post discusses about creating a custom lookup field on a dialog. Following are the methods and code required to achieve the purpose.(Assuming the class is extending the RunbaseBatch)

A lookup method is required in the first place. Below is the sample code to lookup the exchange rates.

private void exchRate_Lookup(FormStringControl _control)
{
SysTableLookup sysTableLookUp;
QueryBuildDataSource qbds;
Query query = new Query();
qbds = query.addDataSource(tableNum(ExchangeRateType));
sysTableLookUp = SysTableLookup::newParameters(tableNum(ExchangeRateType), _control, true);
sysTableLookUp.addLookupfield(fieldNum(ExchangeRateType, Name));
sysTableLookUp.addLookupfield(fieldNum(ExchangeRateType, Description));
sysTableLookUp.parmQuery(query);
sysTableLookUp.performFormLookup();
}

The above method can then be called in the dialog method of the runbase class

public Object dialog()
{
FormStringControl control;
dialog = super();
dlgExcRate = dialog.addField(extendedTypeStr(ExchangeRateTypeName));
control = dlgExcRate.control();
control.registerOverrideMethod(methodstr(FormStringControl, lookUp),methodstr(SampleBatchClass, exchRate_Lookup),this);
return dialog;
}

Note:When we are using this FormStringControl lookup then the batch class “runon” property shouldn’t be “server” That’s all !!!!!!:):):)