How to Set Line Item in Dynamic Mode in Netsuite Suite Script 2.0

Hi,

Suite Script 2.0 have a concept of loading record in static and dynamic mode.
Read setting line item value without dynamic mode here

In Dynamic mode:

Step 1: Load record in dynamic mode:
var myDynamicRecord =  record.load({
                                type: recordtype,
                                id: recordid,
                                isDynamic: true
                            });
*** isDynamic should be true for loading record dynamically.
Step 2: Once loaded, use below code to get line count:
var lineitem = myDynamicRecord.getLineCount({
                                        sublistId: 'item'
                                    });

Step 3: Now iterate through each line:
Step 4: Select line "selectLine" API
Step 5: Set current line using setCurrentSublistValue API.
            You can also use getCurrentSublistValue API for getting value from current sublist as per requirement.
Step 6: Commit Line using "commitLine" API.

var myDynamicRecord =  record.load({
                                type: recordtype,
                                id: recordid,
                                isDynamic: true
                            });
var lineitem = myDynamicRecord.getLineCount({
                                        sublistId: 'item'
                                    });
for(var i=0; i < lineitem; i++)
{
      myDynamicRecord.selectLine({
                                    sublistId: 'item',
                                    line: i
                                });
      myDynamicRecord.setCurrentSublistValue({
                                                        sublistId: 'item',
                                                        fieldId: 'item',
                                                        value: 12345
                                                       });
      myDynamicRecord.commitLine({
                                                        sublistId: 'item'
                                                    });
}
myDynamicRecord.save({
                            enableSourcing: true,
                            ignoreMandatoryFields: true
                        });  

That's it, simple right?

Let us know if you face any issue in dynamic mode or static mode in comment below.

Thanks
Netsuite Guru


Download Netsuite Guru Android App
Follow Me on Linkedin
Our FB Page

Comments