Lookup on the sales form

Hey guys, I have this requirement which I cant really wrap my head around.

When a replacement part is entered by a user(this is setup on product description), we should prompt the user for the original item or SKU. After the user enters the original item, it should lookup the primary pick location (which is a field in inventItemLocation table) for the sku and place that in a field called combinedLocation (its in a custom table) on this form.

A bit more detail; the primary pick location (wMSPickingLocation) is a field in inventItemLocation table and the combined location is on a custom table I created. The mod should take the data from PrimaryPickLocation and update it in the combinedLocation field on the sales form.

I have gotten to a point where, if the item is a replacement, it prompts the user for an original item, and when that is entered it gives this error; “The data source is not embedded within a (parent) data source.”

Any ideas on how to proceed?

Is your lookup customise for the “original item”? Please check the lookup code if it has any query code. Make sure you have correct code syntax to add QueryBuildDataSource.

Hi Vishal, Appreciate your reply.

Within the lookup code, it gives me no error and after a little tweak, it doesnt give me that error anymore, but is replaced with this one “QueryBuildDataSource object not initialized”. The code itself when compiled shows no error. But when i actually perform the lookup on the form, it gives me this error. But when I go back to the code on the lookup method, everything seems fine.

The trace shows error on this line; qbds = qbds1.addDataSource(tableNum(agrSalesLine));

This is how it is defined;
QueryBuildDataSource qbds;
QueryBuildDataSource qbds1;
qbds = qbds1.addDataSource(tableNum(agrSalesLine));

Is there something I need to do on my customTable (agrSalesLine) such that this query is recognized?

I just saw that, that line isnt the rifht way to do it. This is right, however it still gives that error.

qbds1 = query.dataSourceTable(tableNum(InventTable)).addDataSource(tableNum(agrSalesLine));

You have also not provided the relation between the tables:
something like the below code:

query = new Query();
// Data sources
qbdsInventTransOrigin = query.addDataSource(tableNum(inventTransOrigin));

qbdsInventTrans = qbdsInventTransOrigin.addDataSource(tableNum(inventTrans));

Oh sorry, I just didnt include that in here, it was there in code.

Query query = new Query();
QueryBuildDataSource qbdsInventTable;
QueryBuildDataSource qbdsAgrSalesLine;
QueryBuildRange qbr;

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

sysTableLookup.addLookupField(fieldNum(InventTable, ItemId));
sysTableLookup.addLookupField(fieldNum(agrSalesLine, PartsOrigItem));

qbdsInventTable = query.addDataSource(tableNum(InventTable));

qbr = qbdsInventTable.addRange(fieldNum(InventTable, ItemId));

qbdsAgrSalesLine = query.dataSourceTable(tableNum(InventTable)).addDataSource(tableNum(agrSalesLine));