How to get the two different table lookup fields in form control.

Hi all,

I need to lookup on different table fields. how to do this please give me any suggestions ax 2012 R3.

i am using the below code. but it’s getting error.

Error: Failed to execute query because no root data source on the form matches the root datasource on the query.

public void lookup()
{
SysTableLookup sysTableLookup;
Query query;
QueryBuildDataSource qbds;
QueryBuildDataSource qbds1;
QueryBuildRange qbr;

query = new Query();
qbds = query.addDataSource(tableNum(HcmJob));
qbds1 = qbds.addDataSource(tableNum(HcmJobDetail));
qbds1.relations(true);

qbds1.fields().dynamic(NoYes::Yes);
qbds1.addLink( fieldNum(HcmJobDetail, job), fieldNum(HcmJob, RecId));
qbds1.joinMode(JoinMode::InnerJoin);

sysTableLookup = SysTableLookup::newParameters(tableNum(HcmJob), this);
sysTableLookup = SysTableLookup::newParameters(tableNum(HcmJobDetail), this);
sysTableLookup.addLookupfield(fieldnum(HcmJob,JobId));
sysTableLookup.addLookupfield(fieldnum(HcmJobDetail,Description));

sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}

It doesn’t support fields in lookup from multiple tables.

You can add a method to HcmJob table that return the description and use that method in the lookup by addLookupMethod()

(or) build a view with those two tables and use that view in the lookup

Hi kranthi,

Can you please tell me the how can i write the method in HcmJob table is there any example.

Thanks

It seems there is an existing method, you can use that. \Data Dictionary\Tables\HcmJob\Methods\description

Dear Kranthi,

public void lookup()
{

SysTableLookup sysTableLookup;
Query query;
QueryBuildDataSource qbds;
QueryBuildDataSource qbds1;
QueryBuildRange qbr;

query = new Query();
qbds = query.addDataSource(tableNum(HcmJob));

sysTableLookup = SysTableLookup::newParameters(tableNum(HcmJob), this);

sysTableLookup.addLookupfield(fieldnum(HcmJob,JobId));
sysTableLookup.addLookupMethod(tableMethodStr(HcmJob,Description));

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

}

Working fine for me.

Many Thanks Kranthi.