Skip to main content

Command Palette

Search for a command to run...

How to set Sublist line item value using client script in Netsuite SuiteScript 2.x

Published
•1 min read•View as Markdown
A

I am a NetSuite Certified SuiteCloud Developer with over 8 years of work experience.

In This post we will learn how to set sublist field value in client script. We will write a code snippet in client script which will trigger on pageinit and close all the lines of sales order item sublist.

This code is written in Suitescript 2.1

/**
 * @NApiVersion 2.1
 * @NScriptType ClientScript
 */

define(['N/record'], (record)=>{

    const pageInit = (context)=>{
         const currRecord = context.currentRecord;            
         const lines = currRecord.getLineCount({
             sublistId: 'item'
         });

         for(let i=0; i<lines; i++){

            const lineNum = currRecord .selectLine({
                sublistId: 'item',
                line: i
            });

            currRecord.setCurrentSublistValue({
                sublistId: 'item',
                fieldId: 'isclosed',
                value: true,
                ignoreFieldChange: true
            });

            currRecord.commitLine({
                sublistId: 'item'
            });
         }


    }


    return {
        pageInit: pageInit
    };

});

As you can see we are using selectline function to select the line first then using setCurrentSublistValue to finally set the field value and now we should not forget to commit the line

More from this blog

Freelance NetSuite Developer

17 posts

NetSuite Suitecloud Developer | SuiteScript 2.1, SuiteTalk, and Suiteflow Expert | 8+ Years Experience | NetSuite Integration Consultant| NetSuite ERP consultant