How to select Distinct Using X++?
How to select distinct in X++ when actually there is no reserved word like this in X++ for this we do work around to solve this problem .
this example to retrieve distinct account from the lockup table to show it :
public void lookup(FormControl _formControl, str _filterStr)
{
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(MBSR_ACC_PATIENTS), _formControl);
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
;
sysTableLookup.addLookupfield(fieldnum(MBSR_ACC_PATIENTS, ACCOUNT_NO));
sysTableLookup.addLookupfield(fieldnum(MBSR_ACC_PATIENTS, ACCOUNT_NM));
queryBuildDataSource = query.addDataSource(tablenum(MBSR_ACC_PATIENTS));
queryBuildDataSource.addSortField(fieldnum(MBSR_ACC_PATIENTS, ACCOUNT_NO));
queryBuildDataSource.addSortField(fieldnum(MBSR_ACC_PATIENTS, ACCOUNT_NM));
queryBuildDataSource.orderMode(ordermode::GroupBy);
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
super(_formControl, _filterStr);
}
This three lines of code with yellow color are the work around to solve the distinct problem
*This post is locked for comments