๐ฏ Dynamic Filtering in Report Dialogs Based on Selected Parameter


In some reporting scenarios, you may need to dynamically filter available options in one parameter based on the value selected in another. A typical use case is a customer report where, upon selecting a Customer Group, the Customer Account dropdown should only display customers from that group.
To achieve this functionality, youโll need more than just a contract and data provider(DP) class โ a UIBuilder class must also be implemented.
๐ Step 1: Extend the Contract with a UIBuilder Class
To enable the dynamic filter, begin by extending the UIBuilder from your contract class.
[DataContractAttribute,
SysOperationContractProcessingAttribute(classStr(CustomerTransUIBuilder))]
internal final class IBSCustomerSalesContract
{
StartDate startDate;
EndDate endDate;
CustGroupId customerGroup;
CustAccount tradeAccount;
[DataMemberAttribute('StartDate'), SysOperationDisplayOrderAttribute("1")]
public StartDate parmStartDate(StartDate _startDate = startDate)
{
startDate = _startDate;
return startDate;
}
[DataMemberAttribute('EndDate'), SysOperationDisplayOrderAttribute("3")]
public EndDate parmEndDate(EndDate _endDate = endDate)
{
endDate = _endDate;
return endDate;
}
[DataMemberAttribute('CustomerGroup'), SysOperationDisplayOrderAttribute("4")]
public CustGroupId parmCustomerGroup(CustGroupId _customerGroup = customerGroup)
{
customerGroup = _customerGroup;
return customerGroup;
}
[DataMemberAttribute('CustAccount'), SysOperationDisplayOrderAttribute("2")]
public CustAccount parmCustAccount(CustAccount _CustAccount = CustAccount)
{
CustAccount= _CustAccount;
return CustAccount;
}
}
๐ ๏ธ Step 2: Build the UIBuilder Class for Lookup Filtering
Hereโs how to implement the CustomerTransUIBuilder
class to apply filtering logic on the Customer Account field based on the selected Customer Group.
class CustomerTransUIBuilder extends SrsReportDataContractUIBuilder
{
DialogField dialogCustGroup, dialogCustAccountNum;
private void custAccountNumLookUp(FormStringControl custAccountNumLookUp)
{
if (custAccountNumLookUp != null)
{
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(CustTable), custAccountNumLookUp);
Query query = new Query();
QueryBuildDataSource qbds = query.addDataSource(tableNum(CustTable));
sysTableLookup.addLookupfield(fieldNum(CustTable, CustGroup), true);
sysTableLookup.addLookupfield(fieldNum(CustTable, AccountNum), true);
sysTableLookup.addLookupMethod('Name');
sysTableLookup.addLookupMethod('NameAlias');
sysTableLookup.addLookupMethod('phone');
sysTableLookup.setLabel('Phone');
sysTableLookup.addLookupMethod('cityName_BR');
sysTableLookup.addLookupMethod('StateName');
sysTableLookup.addLookupMethod('CountryName');
sysTableLookup.setLabel('Country/Region');
sysTableLookup.addLookupMethod('email');
// ๐ Filter by selected Customer Group
QueryBuildRange qbr = qbds.addRange(fieldNum(CustTable, CustGroup));
qbr.value(dialogCustGroup.value());
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
}
public void postBuild()
{
super();
// ๐ก Bind contract fields to dialog
dialogCustGroup = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(IBSCustomerSalesContract, parmCustomerGroup));
dialogCustAccountNum = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(IBSCustomerSalesContract, parmCustAccount));
}
public void postRun()
{
// ๐ง Override lookup to apply filter logic
dialogCustAccountNum.registerOverrideMethod(
methodStr(FormStringControl, lookup),
methodStr(CustomerTransUIBuilder, custAccountNumLookUp),
this);
}
}
โ Output
Subscribe to my newsletter
Read articles from Donald Kibet directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Donald Kibet
Donald Kibet
I'm a seasoned software developer specializing in customizing D365 F&O applications and creating impressive user interfaces using React and React Native for web and Android applications. Additionally, I develop secure and scalable APIs with Django (Python) or Spring Boot (Java).