How to Set Line Item Values in Netsuite's Suite Script 2.0?

Hi All,

Few days back I wrote about how to set Line Item Values in Netsuite Suite Script 1.0.Now in Suite Script 2.0 is totally different from Suite Script 1.0.
Previously in Suite Script 1.0 we had ability to set line item directly using record.setLineItemValue/Text
now they removed that but in Suite Script 2.0 we still have same functionality.
So no need to select line before setting value , we can directly set the line item value.

Please Note: To read our blog anytime use our Android APP. You can find jobs , referrals and freelancing jobs also. 
To download Netsuite Guru App click .

I wrote a before submit script and there I am able to set line item directly, if we use record.selectLine then JS_Exception was coming as below

org.mozilla.javascript.EcmaError: TypeError: Cannot find function selectLine in object DeferredDynamicRecord. (/SuiteScripts/abhiLineTest.js#76)

/**
 *@NApiVersion 2.x
 *@NScriptType UserEventScript
 */
define(['N/record','N/search'],
    function(record,search) {
    try
    {
        function beforeSubmit(context)
        {
            if ((context.type == context.UserEventType.CREATE) && (context.type == context.UserEventType.COPY))
            {
                return;
            }   
            var customerRecord = context.newRecord;
            var itemcount = customerRecord.getLineCount({sublistId: 'item'});
            log.debug({
                        title: 'item ',
                        details: itemcount
                        });   
                                                        
             
                for(var k=0;(itemcount >= 0) && (k < itemcount);k++)
                {
                   
                    var itemid = customerRecord.getSublistValue({
                                                        sublistId: 'item',
                                                        fieldId: 'item',
                                                        line: k
                                                        });
                   
                    {
                       
                        customerRecord.setSublistValue({
                                                        sublistId: 'item',
                                                        fieldId: 'custcol_update',
                                                        line: k,
                                                        value: 8
                                                        });                           
                    }
                                       
                }                                   
            }   
        }
        return {
            beforeSubmit: beforeSubmit,
           
        };
    }
    catch(e)
    {
        log.error({
        title: 'Error ',
        details: ' ' + e
        });
    }   
    });

Comments

  1. Your blog is so comprehensive but in all examples if you mentioned the business scinario and the target of record type to deploy this will be very. Valuable.

    ReplyDelete
    Replies
    1. thank you so much for reply and suggestion.
      we will try to add such details also.
      Keep visiting and please use our FB group for any query.

      Delete

Post a Comment

Thanks for you message, please join us on Facebook and Linkedin