问题
This is code that should work with any base system added to Tables\ProdBOM. Somehow the query is stripping out data from fields.
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);
// This doesn't work \/
sysTableLookup.addLookupMethod(tablemethodstr(ProdBOM, configId));
// This doesn't work /\
sysTableLookup.addLookupMethod(tablemethodstr(ProdBOM, itemName));
sysTableLookup.addLookupfield(fieldNum(ProdBOM, ProdLineType));
sysTableLookup.addLookupfield(fieldNum(ProdBOM, InventTransId));
sysTableLookup.performFormLookup();
}
In the Tables\ProdBOM\Methods\configId, you can clearly see something is awry with this code. What's going on??
//BP Deviation documented
display ConfigId configId()
{
ProdBOM pb;
;
select firstonly pb where pb.RecId == this.RecId;
info(strfmt("Bad: [%1, %2], Good:[%3, %4]", this.ItemId, this.InventDimId, pb.ItemId, pb.InventDimId));
return this.inventDim().ConfigId;
}
回答1:
So I figured it out. In Classes\SysTableLookup\buildSelectionList
, it adds all of the fields that are included in the lookupfields to the QBDS.addSelectionField, which appears to drop it off the return fields??
It doesn't strip out RecId though, so I was able to just create another display method that re-selects the record using the recId.
//BP Deviation documented
display ConfigId configIdFromRecId()
{
return InventDim::find((select firstonly prodBOM where prodBOM.RecId == this.RecId).InventDimId).configId;
}
回答2:
You can force the QueryBuildDatasource to load needed fields by modifying its fieldlist. You can use QueryBuildDatasource.fields().addField()
method to add fields wich schould be fetched and are in use by your LookupMethod
来源:https://stackoverflow.com/questions/17843756/lookup-method-bug-with-systablelookup