Основная проблема, которую я сразу вижу:
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));
}