我立即看到的主要问题是:
prodtable.inventrefid == 'ZPR00000165'
inventRefId
将是你的SalesId
,这ZS00000011
不是你的ProdId
。
下面是一个更正确的查询示例。您可以通过将两个选择连接在一起来细化它,以便将所有相关ProdTable
记录与给定的所有 记录一起获取,您还可以在查询中指定字段,这样您就不会返回整个缓冲区。SalesLine
SalesId
SalesLine salesLine;
ProdTable prodTable;
/*
This just chooses the first sales line with that salesid. You would need to join these together
if you wanted to do all sales lines in one query.
*/
select firstOnly salesLine
where salesLine.SalesStatus == SalesStatus::Backorder &&
salesLine.SalesId == 'ZS00000011';
while select prodTable
where prodTable.InventRefTransId == salesLine.InventTransId &&
prodTable.InventRefId == salesLine.SalesId &&
prodTable.InventRefType == InventRefType::Sales
{
info(strFmt("Found related ProdTable record %1 - %2 (%3)", prodTable.ProdId, prodTable.CollectRefProdId, prodTable.RecId));
}