fetching records in lookup

i need to fetch the customer names from the sales table who are having the sales orders, i did that. but it is showing the customer names duplicates because one customer may having the number of sales order now i want to show customer name only one time even they are having many sales orders. in lookup i write the all code as shown below

public void lookup()
{
//super();
SalesTable SalesTable;

// Declaration
Query LookupQuery = new Query();
QueryBuildDataSource LookupQueryBuildDataSource;
QueryBuildRange LookupQueryBuildRange;
SysTableLookup CustomSysTableLookup = SysTableLookup::newParameters(tableNum(SalesTable), this);
;

// Add DataSource
LookupQueryBuildDataSource = LookupQuery.addDataSource(tableNum(SalesTable));
// Add fields that you want in Lookups

CustomSysTableLookup.addLookupField(fieldNum(SalesTable, SalesName));
CustomSysTableLookup.addLookupField(fieldNum(SalesTable, CustAccount));

// Execute the Query
CustomSysTableLookup.parmQuery(LookupQuery);
CustomSysTableLookup.performFormLookup();
}

is there any way to do that can any one help me please?..

You can group records by CustAccount (use QueryBuildDataSource.addGroupByField()); obviously SalesName make no sense in that case.

hi martin, what you said is working but when the control is blank then it is working, after selecting a value from the lookup, if we click on the lookup button again it is showing duplicates. now my code is this.

public void lookup()
{
//super();
SalesTable SalesTable;

// Declaration
Query LookupQuery = new Query();
QueryBuildDataSource LookupQueryBuildDataSource;
QueryBuildRange LookupQueryBuildRange;
SysTableLookup CustomSysTableLookup = SysTableLookup::newParameters(tableNum(SalesTable), this);
;

// Add DataSource

LookupQueryBuildDataSource = LookupQuery.addDataSource(tableNum(SalesTable));
// Add fields that you want in Lookups

CustomSysTableLookup.addLookupField(fieldNum(SalesTable, SalesName));
CustomSysTableLookup.addLookupField(fieldNum(SalesTable, CustAccount ));
LookupQueryBuildDataSource.addGroupByField(fieldnum(SalesTable, SalesName));
LookupQueryBuildDataSource.addGroupByField(fieldnum(SalesTable, CustAccount));

// Execute the Query
CustomSysTableLookup.parmQuery(LookupQuery);
CustomSysTableLookup.performFormLookup();
}

can you please ot solve this?

I don’t know what problem do you have. But you have to understand that SalesName is name of order, not name of customer (that’s just a default value). Users can change it to whatever they need, so you can have many different SalesName values for a single CustAccount.