Saturday, April 29, 2023

AX / D365FO – GROUPBY ON LOOKUP

 I have a custom lookup with a GroupBy inside Query statement

First time, when the is nothing choosen the group by works fine. If I choose something from list and again want to change it, now the group by is lost.

To solve the issue simply use sysTableLookup.parmUseLookupValue(false) like show in below code

        public void lookup()
        {
            Query query = new Query();
            QueryBuildDataSource queryBuildDataSource;
            QueryBuildRange queryBuildRange;
    
            SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(ots_GuidedSalesOrderEntryRules), this);
    
            sysTableLookup.addLookupField(fieldNum(ots_GuidedSalesOrderEntryRules, ToleranceType));
    
            queryBuildDataSource = query.addDataSource(tableNum(ots_GuidedSalesOrderEntryRules));

            QueryGroupByField queryGroupByField = queryBuildDataSource.addGroupByField(fieldNum(ots_GuidedSalesOrderEntryRules, ToleranceType));
            sysTableLookup.parmUseLookupValue(false);
            sysTableLookup.parmQuery(query);
    
            sysTableLookup.performFormLookup();
        }

No comments:

Post a Comment