✏️ Explanatory Question
The lookup() method is a standard method on the field of the form data source. This method is called when a lookup operation is attempted on a data source field. If data that's shown in the lookup form must be customized with some filter, the lookup() method should be overridden.
Example
You have a custom form with a table named TrainingMaster. The table has a field named TrainerID that creates a foreign key with the TrainerTable. TrainerTable has an enum field called TrainerType that has two values: Technical and Functional. The lookup in the TrainerID field should display only technical trainers.
The coding pattern can be as follows:
[DataSource]
class TrainingMaster
{
[DataField]
class TrainerID
{
public void lookup(FormControl _formControl, str _filterStr)
{
SysTableLookup sysTableLookup =
SysTableLookup::newParameters(tableNum(TrainerTable),_formControl);
Query query = new Query();
QueryBuildDataSource qbds;
qbds= query.addDataSource(tableNum(TrainerTable));
qbds.addRange(fieldNum(TrainerTable,
TrainerType)).value(enum2Str(TrainerType::Technical));
sysTableLookup.addLookupfield(fieldNum(TrainerTable,TrainerID));
sysTableLookup.addLookupfield(fieldNum(TrainerTable,TrainerName));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
}
}