Custom Lookup and Group By Problem

Hi frnds,

Why group by clauses are disabled in lookups when the field using the lookup is not empty?

I want to do a custom lookup on a field in a form. The table CTable looks like this:

Val Spec
------------
A   alpha
A   beta
A   gamma
B   delta
C   epsilon

The look up only concerns the Val column which is defined using an EDT with a basic relationship on it: Val == CTable.Val

The lookup obviously gives me a list like this:

A
A
A
B
C

Let’s to a group by to get rid of all the duplicated As, I thought! Something along the lines of:

QueryBuildDataSource.orderMode(OrderMode::GroupBy);
QueryBuildDataSource.addGroupByField(fieldNum(CTable, Val));

Now comes the strange behaviour I have and the actual point of my question. On an empty field, the group by is correctly executed and I get this:

A
B
C

Now let’s select “A” in the lookup, then perform the lookup again because I wanted to click on “B” instead. The group by is now disabled for unknown reasons and I get the same look up results as the first I had before.

Why is it so? How can I overcome that?

Rgds

BK

You can disable this behavior by setting useLookupValues in SysTableLookup to false. Unfortunately I don’t know exactly why AX does that. I suspect that it changes OrderMode to OrderBy.

A lot thanks Martin!!

its working perfactly

Rgds

BK

could you please where isthe option set it false “setting useLookupValues in SysTableLookup to false”

just check this lookup method

public void lookup()

{

SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(RKM_SectionInputMaster), this);

Query query = new Query();

QueryBuildDataSource queryBuildDataSource,queryBuildDataSource1;

QueryBuildRange qbr,qbr1,qbr2;

QueryBuildLink QueryBuildLink1;

;

//breakpoint;

queryBuildDataSource = query.addDataSource(tablenum(RKM_SectionInputMaster));

queryBuildDataSource.addRange(fieldnum(RKM_SectionInputMaster, InventSiteId)).value(InventSiteId.text());

sysTableLookup.addLookupfield(fieldnum(RKM_SectionInputMaster, RKM_InputCounterId),True);

sysTableLookup.addLookupfield(fieldnum(RKM_SectionInputMaster, RKM_InputCounterName));

sysTableLookup.addLookupfield(fieldnum(RKM_SectionInputMaster, ALE_InputItemId));

sysTableLookup.addLookupfield(fieldnum(RKM_SectionInputMaster, ALE_InputItemName));

sysTableLookup.addLookupfield(fieldnum(RKM_SectionInputMaster, RKM_ItemConfiguration));

sysTableLookup.addLookupfield(fieldnum(RKM_SectionInputMaster, InventLocationId));

sysTableLookup.parmQuery(query);

sysTableLookup.parmUseLookupValue(False);

sysTableLookup.performFormLookup();

// super();

}