RE: Transform sales order to Return Authorization with specific items – SuiteScript 2.0
I need to transform a sales order to return authorization with specific line items, not will all line items available on the sales order. Let’s say I have a sales order created with 3 items
- Item one with qty 2
- Item two with qty 1
- Item three with qty 4
this order fulfilled completely and billed. Now, the customer wanted to return Item two with qty 1 and Item three with qty 2, I want to transform (using suite script 2.0) my sales order to return authorization with only return items, I don’t want to include items that are not returned.
Returned items are available in an array;
const returned_items = [{ item: 'item two', qty: 1 }, { item: 'item three', qty: 2 }]; var returnAuthorizationRecord = record.transform({ fromType: record.Type.SALES_ORDER, fromId: orderId, toType: record.Type.RETURN_AUTHORIZATION, isDynamic: true, defaultValues: { customform: CUSTOM_FORMS_RMA.CREDIT } }); const lineCount = returnAuthorizationRecord.getLineCount({ sublistId: 'item' }); for (var i = 0; i < lineCount; i++) { returnAuthorizationRecord.selectLine({ sublistId: 'item', line: i }); // Do I need to first remove all line items and then add retuned items available in array returnAuthorizationRecord.removeLine({ sublistId: 'item', line: 3, ignoreRecalc: true }); // Or loop through each line and match with item, if item matches then update accordingly if not then remove from the list? } returnAuthorizationRecord.save();
As an FYI–we answered this on stackoverflow for you with the actual code.