let queryForVendorSubsidiary = `SELECT
itemVendor.subsidiary AS subsidiary,
FROM
item
LEFT JOIN
itemVendor ON item.ID = itemVendor.item
LEFT JOIN
(SELECT
aggregateItemLocation.item AS item,
aggregateItemLocation.LOCATION AS LOCATION,
LOCATION.subsidiary AS subsidiary,
aggregateItemLocation.reorderpoint AS reorderpoint_crit,
aggregateItemLocation.quantityavailable AS quantityavailable_crit,
aggregateItemLocation.quantityonorder AS quantityonorder_crit,
aggregateItemLocation.quantitybackordered AS quantitybackordered_crit,
aggregateItemLocation.preferredstocklevel AS preferredstocklevel_crit,
LOCATION.subsidiary AS subsidiary_crit
FROM
aggregateItemLocation
LEFT JOIN
LOCATION ON aggregateItemLocation.LOCATION = LOCATION.ID
) aggregateItemLocation_SUB ON item.ID = aggregateItemLocation_SUB.item
WHERE
item.itemtype IN ('Assembly', 'InvtPart')
AND (
(
((NVL(aggregateItemLocation_SUB.reorderpoint_crit, 0) - NVL(aggregateItemLocation_SUB.quantityavailable_crit, 0)) - NVL(aggregateItemLocation_SUB.quantityonorder_crit, 0)) + NVL(aggregateItemLocation_SUB.quantitybackordered_crit, 0) >= 0
AND
((NVL(aggregateItemLocation_SUB.preferredstocklevel_crit, aggregateItemLocation_SUB.reorderpoint_crit) - NVL(aggregateItemLocation_SUB.quantityavailable_crit, 0)) - NVL(aggregateItemLocation_SUB.quantityonorder_crit, 0)) + NVL(aggregateItemLocation_SUB.quantitybackordered_crit, 0) > 0
)
OR
(
((NVL(aggregateItemLocation_SUB.reorderpoint_crit, 0) - NVL(aggregateItemLocation_SUB.quantityavailable_crit, 0)) - NVL(aggregateItemLocation_SUB.quantityonorder_crit, 0)) + NVL(aggregateItemLocation_SUB.quantitybackordered_crit, 0) IS NULL
)
)
AND aggregateItemLocation_SUB.reorderpoint_crit >= 0
AND item.supplyreplenishmentmethod = 'REORDER_POINT'
AND (
CASE
WHEN aggregateItemLocation_SUB.subsidiary = itemVendor.subsidiary THEN 1
ELSE 0
END = 1
)
AND itemVendor.vendor = ?`;
const queryResult = query.runSuiteQL({ query: queryForVendorSubsidiary, params: [vendorField] });
if (queryResult.results.length > 0) {
for (let i = 0; i < queryResult.results.length; i++) {
// log.debug("before query.runSuiteQL");
itemArray.push(queryResult.results[i].values[0]);
}
}