Hello everyone,
I created a SuiteScript that when after submitting a PO, it will go into the Sales Order it was created from and update some transaction line items.
In order to target the Sales Order invoices, I had needed to create a search variable.
const invoiceSearch = search.create({ type: search.Type.INVOICE, filters: [['createdfrom', search.Operator.ANYOF, salesOrderId]],columns: ['internalid']}),
invoiceResults = invoiceSearch.run().getRange({ start: 0, end: 1000 });
Once it created the search, it would look the the invoices and if there an invoice, the ID would generate.
if (invoiceResults.length > 0) {
var invoiceId = invoiceResults[0].getValue({ name: 'internalid' });
}
This works great when it handles one Invoice, but it does not work on multiple.
I have an SO in my sandbox that has three invoices attached. The IDs are labeled 612, 613 and 614.
My execution log showed that it loaded INV 612 three times and only updated that one, 613 and 614 were not selected.
I am currently unable to set a "for each Invoice ID" function, that should resolve the issue and allow for my script to work. How would I do this for each ID?