Thank you Vishal,
I’ve achieved the result. Through the below code.
void lookup(FormControl control, str _filterStr)
{
//super(control, _filterStr);
Query query = new Query();
QueryRun qr;
QueryBuildDataSource queryBuildDataSource;
QueryBuildDataSource queryBuildDataSource2;
QueryBuildRange queryBuildRange;
QueryBuildRange queryBuildRange2;
SysTableLookup sysTableLookup;
CW005_LookupTemp lookUp;
SalesAgreementHeader salesAgreementHeaderInstance;
CW005_AuthorizedSubcontractingCustomers authSubCont;
;
delete_from lookUp;
queryBuildDataSource = query.addDataSource(tableNum(SalesAgreementHeader));
queryBuildDataSource2 = query.addDataSource(tablenum(CW005_AuthorizedSubcontractingCustomers));
//Joining the tables
queryBuildDataSource2.joinMode(JoinMode::InnerJoin);
//linking the two table through the common fields
//queryBuildDataSource.addLink(fieldNum(SalesAgreementHeader,RecId),fieldNum(CW005_AuthorizedSubcontractingCustomers,AgreementHeaderDefault));
//setting the range in the datasource one
queryBuildRange = queryBuildDataSource.addRange(fieldnum(SalesAgreementHeader,RecId));
queryBuildRange.value(queryValue(salesAgreementHeader.RecId));
//setting the range in the datasource two
queryBuildRange2 = queryBuildDataSource2.addRange(fieldNum(CW005_AuthorizedSubcontractingCustomers, AgreementHeaderDefault));
queryBuildRange2.value(queryValue(salesAgreementHeader.RecId));
// running into the query dataset
qr = new QueryRun(query);
while(qr.next())
{
authSubCont = qr.get(tableNum(CW005_AuthorizedSubcontractingCustomers));
select salesAgreementHeaderInstance where salesAgreementHeaderInstance.recid == authSubCont.AgreementHeaderDefault
&& salesAgreementHeaderInstance.CustAccount != authSubCont.CustTable;
if(salesAgreementHeaderInstance)
{
lookUp.CustAccount = salesAgreementHeaderInstance.CustAccount;
lookUp.CustAccount = authSubCont.CustTable;
lookUp.Insert();
//info(strFmt(’%1’, lookUp.CustAccount));
}
else
{
salesAgreementHeaderInstance = qr.get(tableNum(SalesAgreementHeader));
select firstOnly CustAccount from salesAgreementHeaderInstance where salesAgreementHeaderInstance.RecId == salesAgreementHeader.RecId;
lookUp.CustAccount = salesAgreementHeaderInstance.CustAccount;
lookUp.Insert();
//info(strFmt(’%1’, lookUp.CustAccount));
}
}
//Create an instance of SysTableLookup with the form control passed in
sysTableLookup = SysTableLookup::newParameters(tablenum(CW005_LookupTemp), control);
//Add the fields to be shown in the lookup form
sysTableLookup.addLookupfield(fieldnum(CW005_LookupTemp, CustAccount), true);
// Perform lookup
sysTableLookup.performFormLookup();
}