Reputation: 1125
I created a custom lookup on the ProdBom table and it just displays the BOM items for a given production order so that a user can select only items listed on the BOM. I also want them to be able to select the produced BOM item (ProdTable.ItemId) in the list (1 extra item). How could I do this?
Here is my current lookup:
static void lookupItemIdBOMSubset(FormStringControl _ctrl,
ProdId _prodId)
{
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(ProdBOM), _ctrl);
Query query = new Query();
QueryBuildDataSource qbds = query.addDataSource(tablenum(ProdBOM));
;
qbds.addRange(fieldnum(ProdBOM, ProdId)).value(queryValue(_prodId));
qbds.addSortField(fieldnum(ProdBOM, LineNum), SortOrder::Ascending);
sysTableLookup.parmQuery(query);
sysTableLookup.addLookupfield(fieldnum(ProdBOM, LineNum));
sysTableLookup.addLookupfield(fieldnum(ProdBOM, bomId));
sysTableLookup.addLookupfield(fieldnum(ProdBOM, ItemId), true);
sysTableLookup.addLookupMethod(tablemethodstr(ProdBOM, itemName));
sysTableLookup.addLookupfield(fieldnum(ProdBOM, ProdLineType));
sysTableLookup.addLookupfield(fieldnum(ProdBOM, InventTransId));
sysTableLookup.performFormLookup();
}
Upvotes: 0
Views: 564
Reputation: 1369
You could try using a temp version of ProdBOM, populate it with the necessary information and use the buffer to perform the lookup:
ProdBom tmpProdBom,
prodBom;
ProdTable prodTable;
;
//Set table as temp buffer
tmpProdBom.setTmp();
//First record, insert into temp buffer
select prodTable where prodTable.prodId = _prodId;
tmpProdBom.lineNum = 0;
tmpProdBom.bomId = "";
tmpProdBom.ItemId = prodTable.itemId;
//...etc for each field you have/want to be available
tmpProdBom.insert();
//Insert the rest of the records
while select prodBom where prodBom.ProdId = _prodId
{
tmpProdBom.lineNum = prodBom.lineNum;
tmpProdBom.bomId = prodBom.bomId;
//...etc for each field you want available
tmpProdBom.insert();
}
sysTableLookup.parmTmpBuffer(tmpProdBom);
sysTableLookup.addLookupfield(fieldNum(ProdBOM, LineNum));
//etc
sysTableLookup.performFormLookup();
I don't have an adequate form set up currently to test this lookup, so you may need to play around with it in a testing environment, but I have used a similar method in the past.
Upvotes: 1