RE: How to add a sublist row to a sales order from another record (item fulfilment)

Hi there,

We are trying to build a script to add a promotion on a sales order from the item fulfilment page. We are running into the following error:
USER_ERROR Please enter value(s) for: Promotion, Coupon Code

We have noted that if you run the script on the sales order page using context.currentRecord in place of the salesOrder variable below, it will work; however when we try to load a record object using the code below from both the sales order or item fulfilment page we get the error above.

DOESNT WORK:
var salesOrder = record.load({
“type”: record.Type.SALES_ORDER,
“id”: orderId,
“isDynamic”: true
});
salesOrder.insertLine({“sublistId”: “promotions”, “line”: 0});
salesOrder.selectLine({“sublistId”: “promotions”, “line”: 0});
salesOrder.setCurrentSublistValue({“sublistId”: “promotions”, “fieldId”: “promocode”, “value”: 7});
salesOrder.setCurrentSublistValue({“sublistId”: “promotions”, “fieldId”: “couponcode”, “value”: 6});
salesOrder.commitLine({“sublistId”: “promotions”});

WORKS:
var salesOrder = context.currentRecord;
salesOrder.insertLine({“sublistId”: “promotions”, “line”: 0});
salesOrder.selectLine({“sublistId”: “promotions”, “line”: 0});
salesOrder.setCurrentSublistValue({“sublistId”: “promotions”, “fieldId”: “promocode”, “value”: 7});
salesOrder.setCurrentSublistValue({“sublistId”: “promotions”, “fieldId”: “couponcode”, “value”: 6});
salesOrder.commitLine({“sublistId”: “promotions”});

danielallin Rookie Asked on August 5, 2020 in SuiteScript.
Add Comment
1 Answers

I’ve personally had no luck adding to the promotions sublist via client script, I only get errors there. Do it serverside instead.

I’d also recommend using Record.selectNewLine instead of your select and insert. You should only need to set the promocode, couponcode should source from the promocode.

Intermediate Answered on August 6, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.