我需要帮助来从prodtable获取与销售线相关的数据。我的任务是获取与当前salesid相关的所有Prodid。相关字段prodtable.inventrefid == salesline.salesid。但是这些值的加入有点不同,所以我没有数据。Inventrefid有例如。ZPR0000011,销售编号为ZS00000011。
salesline tablebuffer = this.cursor();
while select ProdId, CollectRefProdId from prodtable where prodtable.inventrefid == 'ZPR00000165'
我立即看到的主要问题是:
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));
}
问题是我不知道我是否需要在选择中使用Backorder和:: Sales。而且因为当我只进行prodtable.inventrefid == salesline.salesid时它不起作用,所以我在想问题是salesid完全是ZS,而实际上是ZPR。
@RadosławMierzejewski尝试创建选择语句时查看表关系会很有帮助。看看
\Data Dictionary\Tables\ProdTable\Relations\SalesOrder
我如何知道选择中需要的那些。很高兴我能帮上忙!