Search code examples
lookupaxaptadynamics-ax-2009

Custom lookup select issue


The idea is to contruct a lookup with unique Employer name. The lookup works fine but when I select a value and then select the lookup button again and click on the place marked in RED, there are duplicate values, which is wrong.

Kindly refer the snippet and snapshot

QueryBuildDataSource    qbds;
Query                   query = new Query();
FormStringControl       control = dialog.formRun().controlCallingMethod();
SysTableLookup          sysTableLookup =  SysTableLookup::newParameters(tablenum(VendTable), control);
;

qbds  = query.addDataSource(tablenum(VendTable));
qbds.addGroupByField(fieldnum(VendTable,EmployerName));
sysTableLookup.addLookupfield(fieldnum(VendTable, EmployerName));

sysTableLookup.parmQuery(query);
sysTableLookup.parmUseLookupValue(false);
sysTableLookup.performFormLookup();

enter image description here enter image descrip![enter image description heretion here]2


Solution

  • Make a view on table VendTable and field EmployerName and a count of RecId, then base the lookup on the view.

    As shown below for CustTable and CustGroup:

    enter image description here

    enter image description here