1
votes

I have a client script attached to a Suitelet sublist form. The sublist has checkboxes. I need to get the sales order records connected to each sublist line that is checked (getting from saved search). Then I need to load that sales order record and close all of the line items on the record. I'm able to set a body field on the sales order record but I cannot set the sublist fields. I can get the values from the item sublist but I cannot set them.

Is it possible to set the sublist field on an existing Sales Order record from a client script that is attached to a suitelet? If so how?

I've tried to do it in the standard way, the dynamic way and using promises. I am aware that there are two methods to setting sublists depending on if you use dynamic mode when you load the record or not.

        var salesOrderRec = record.load.promise({
            type: record.Type.SALES_ORDER,
            id: salesOrderId
        });
        salesOrderRec.then(function (objRecord) {
            var itemLines = objRecord.getLineCount({
                sublistId: 'item'
            });
            console.log("itemLines: " + itemLines);
            for (var i = 0; i < itemLines; i++) {
                var isClosed = objRecord.getSublistValue({
                    sublistId: 'item',
                    fieldId: 'isclosed',
                    line: i,
                });
                console.log("isClosed: " + i + ", " + isClosed);
                objRecord.setSublistValue({
                    sublistId: 'item',
                    fieldId: 'isclosed',
                    line: i,
                    value: true
                });
            }
            var recordId = objRecord.save();
        });
1
Are you getting an error, or does it just not close the line?Nathan Sutherland
No error, just wasn't setting anything. I figured out that if I load the record in dynamic mode and then use the select line, setCurrentSublistValue() and commitLine() it works. So I learned there are different ways to get and set sublist values depending on if you are using standard or dynamic mode. I'm stll wondering, do I need to use the promise version of the record loading api because this is a Client Script? Either way, I got this working.Gus
No, you don't have to use the promise version.Nathan Sutherland

1 Answers

2
votes
       var salesOrderRec = record.load.promise({
            type: record.Type.SALES_ORDER,
            id: salesOrderId,
            isDynamic: true
        });
        salesOrderRec.then(function (objRecord) {
            var itemLines = objRecord.getLineCount({
                sublistId: 'item'
            });
            console.log("itemLines: " + itemLines);
            for (var i = 0; i < itemLines; i++) {
                objRecord.selectLine({
                    sublistId: "item",
                    line: i
                });
                //console.log("isClosed: " + i + ", " + isClosed);
                objRecord.setCurrentSublistValue({
                    sublistId: 'item',
                    fieldId: 'isclosed',
                    line: i,
                    value: true
                });
                objRecord.commitLine({ sublistId: "item" });
            }
            var recordId = objRecord.save();
        });