In this blog post, I will show you how to develop a multi selection lookup for report parameters for multi selection value in D365FnO using X++.
In the previous blog post, we have discussed about Report Development. In this post we will discuss about how we develop a report with multi selection lookup for report parameters and get values in DP class.
A multi selection lookup is a lookup that allows the user to select one or more than one value from a list of options. This can be useful for filtering data based on multiple criteria, such as selecting multiple customers or products.
To create a multi selection lookup, I will take help of RDP report classes like Data contract, UIBuilder and Data provider.
Create a data contract class:
[
DataContractAttribute,
SysOperationGroupAttribute('EmployeeName',"EmployeeName",'1'),
SysOperationGroupAttribute('CustomerNum',"CustomerNum",'2'),
SysOperationContractProcessingAttribute(classstr(MultiSelectionLookupUIBuilder),SysOperationDataContractProcessingMode::CreateUIBuilderForRootContractOnly)
]
class MultiSelectionLookupDC
{
List EmployeeName;
List CustomerNum;
[
DataMemberAttribute('EmployeeName'),
SysOperationLabelAttribute(literalstr("EmployeeName")),
SysOperationHelpTextAttribute(literalstr("EmployeeName")),
SysOperationGroupMemberAttribute('EmployeeName'),
SysOperationDisplayOrderAttribute('1')
AifCollectionTypeAttribute('Employee name',Types::String,extendedtypestr(Name))
]
public List parmEmployeeName(List _employeeName = employeeName)
{
employeeName = _employeeName;
return employeeName;
}
[
DataMemberAttribute('CustomerNum'),
SysOperationLabelAttribute(literalstr("CustomerNum")),
SysOperationHelpTextAttribute(literalstr("CustomerNum")),
SysOperationGroupMemberAttribute('CustomerNum'),
SysOperationDisplayOrderAttribute('2')
AifCollectionTypeAttribute('Customer number',Types::String,extendedtypestr(AccountNum))
]
public List parmCustomerNum(List _customerNum = customerNum)
{
customerNum = _customerNum;
return customerNum;
}
}
Create a UIBuilder class:
public class MultiSelectionLookupUIBuilder extends SrsReportDataContractUIBuilder
{
MultiSelectionLookupDC rdpcontract;
DialogField dialogEmployeeName;
DialogField dialogCustomerNum;
public void build()
{
rdpcontract = this.dataContractObject() as MultiSelectionLookupDC;
dialogEmployeeName = this.addDialogField(methodStr(MultiSelectionLookupDC,parmEmployeeName),rdpContract);
dialogCustomerNum = this.addDialogField(methodStr(MultiSelectionLookupDC,parmCustomerNum),rdpcontract);
}
public void CustomerNumLookup(FormStringControl _control)
{
Query query;
query = new Query();
query.addDataSource(tableNum(CustTable));
query.dataSourceTable(tableNum(CustTable)).fields().addField(fieldNum(CustTable, AccountNum));
SysLookupMultiSelectGrid::lookup(query, _control, _control,_control, conNull());
}
public void EmployeeNameLookup(FormStringControl _control)
{
Query query;
query = new Query();
query.addDataSource(tableNum(DirPerson));
query.dataSourceTable(tableNum(DirPerson)).fields().addField(fieldNum(DirPerson,Name));
SysLookupMultiSelectGrid::lookup(query, _control, _control,_control, conNull());
}
public void postBuild()
{
Dialog localDaialogObj = this.dialog();
super();
dialogEmployeeName = this.bindInfo().getDialogField(this.dataContractObject(),methodStr(MultiSelectionLookupDC,parmEmployeeName));
dialogEmployeeName.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(MultiSelectionLookupUIBuilder,EmployeeNameLookup), this);
dialogCustomerNum = this.bindInfo().getDialogField(this.dataContractObject(),methodStr(MultiSelectionLookupDC,parmCustomerNum));
dialogCustomerNum.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(MultiSelectionLookupUIBuilder,CustomerNumLookup), this);
}
Public void PostRun()
{
MultiSelectionLookupDC contract = this.dataContractObject();
}
}
Create a Data provider class:
[
SRSReportParameterAttribute(classstr(MultiSelectionLookupDC))
]
class MultiSelectionLookupDP extends SRSReportDataProviderBase
{
MultiSelectionLookupDC multiSelectionContract;
CustomerVisit customerVisit; // Source table
List employeeName;
List customerNum;
[SysEntryPointAttribute(false)]
public void processReport()
{
Query query;
QueryRun queryRun;
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
ListEnumerator employeeNameList, customerNumList;
multiSelectionContract = new MultiSelectionLookupDC();
multiSelectionContract = this.parmDataContract() as MultiSelectionLookupDC;
query = new Query();
employeeName = multiSelectionContract.parmEmployeeName();
customerNum = multiSelectionContract.parmCustomerNum();
queryBuildDataSource = query.addDataSource(tableNum(customerVisit));
if(employeeName)
{
employeeNameList = employeeName.getEnumerator();
while (employeeNameList.moveNext())
{
query.dataSourceTable(tableNum(customerVisit)).addRange(fieldNum(customerVisit,EmployeeName)).value(queryValue(employeeNameList.current()));
}
}
if(customerNum)
{
customerNumList = customerNum.getEnumerator();
while (customerNumList.moveNext())
{
query.dataSourceTable(tableNum(customerVisit)).addRange(fieldNum(customerVisit,customerNum)).value(queryValue(customerNumList.current()));
}
}
queryRun = new QueryRun(query);
while (queryRun.next())
{
customerVisit = queryRun.get(tableNum(CustomerVisit));
}
}
}
Screenshot is attached to view the multi selection lookup at report generation time.
That’s it! You have successfully created an multi selection lookup for report parameters in D365FnO. I hope you found this blog post useful and informative. Share with others.