fetching records from sales table

hi i need to fetch the CustName from the custTable those are having the salesorders only. i created a form in that i wrote a lookup as follows but it is showing all customers. can any one help me to fetch the CustName those are having the sales Orders?

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

// Declaration
Query LookupQuery = new Query();
QueryBuildDataSource LookupQueryBuildDataSource;
QueryBuildRange LookupQueryBuildRange;
SysTableLookup CustomSysTableLookup = SysTableLookup::newParameters(tableNum(CustTable), this);
;
// Add fields that you want in Lookups

CustomSysTableLookup.addLookupField(fieldNum(CustTable, Name));
CustomSysTableLookup.addLookupField(fieldNum(CustTable, AccountNum));

// Add DataSource
LookupQueryBuildDataSource = LookupQuery.addDataSource(tableNum(CustTable));

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

Hi Venkatesh,

add the addRangein the query.

Thanks,

Valeru.

without adding the range i got the solution by writing the folowing lookup code…

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();
}

thanks for u r reply…