Here we are going to see how we can filter / override the lookup on the form control.
Scenario, we need to override the TemplateID lookup based on the ProjGroupId field.
1. First we need to copy the OnLookup event on the form field control.
2. Create a new class and past the above event
///
///
///
/// Scenario, we need to override the TemplateID lookup based on the ProjGroupId field.
1. First we need to copy the OnLookup event on the form field control.
2. Create a new class and past the above event
///
///
///
///
[FormControlEventHandler(formControlStr(MkQuoteCreate, TemplateId), FormControlEventType::Lookup)]
public static void TemplateId_OnLookup(FormControl sender, FormControlEventArgs e)
{
//
}
3. Now the actual lookup code.
FormRun callerFormRun;
MKQuotations quotations;
//Get the Data source of the form
quotations = sender.dataSourceObject().cursor();
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(MKTemplateTable), sender);
sysTableLookup.addLookupField(fieldNum(MKTemplateTable, TemplateId));
sysTableLookup.addLookupField(fieldNum(MKTemplateTable, Description));
queryBuildDataSource = query.addDataSource(tableNum(MKTemplateTable));
queryBuildRange = queryBuildDataSource.addRange(fieldNum(MKTemplateTable, ProjGroupId));
queryBuildRange.value(quotations.ProjGroupId);
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
FormControlCancelableSuperEventArgs ce = e as FormControlCancelableSuperEventArgs;
//cancel super() to prevent error.
if (ce)
{
ce.CancelSuperCall();
}
A few things we can note here are...
1. To get the Datasource cursor we need to use the "sender" parameter as below.
quotations= sender.dataSourceObject().cursor();
Eg:
ecoResProduct = sender.formRun().dataSource(formDataSourceStr(EcoResProductDetailsExtended, EcoResProduct)).cursor();