Gus
Gus

Reputation: 73

Set Sublist Fields on Existing Records from Client Script attached to Suitelet

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();
        });

Upvotes: 1

Views: 1942

Answers (1)

Gus
Gus

Reputation: 73

       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();
        });

Upvotes: 2

Related Questions