Search code examples
netsuitesublist

NetSuite Update Customer subscription entries


I'm triing to update customer subscriptions list in netsuite.

var itemCount = recLead.getLineItemCount('subscriptions');
for (var i = 1; i < itemCount; i++ ) {  recLead.setCurrentLineItemValue('subscriptions', 'subscribed', 'T');}

But error throws: Notice (SuiteScript) You have attempted an invalid sublist or line item operation. You are either trying to access a field on a non-existent line or you are trying to add or remove lines from a static sublist.


Solution

  • If you are planning on using the "current" line item function, then you do need to select the line to use. As below:

    var itemCount=recLead.getLineItemCount('subscriptions');
    for(var i=1;i<=itemCount;i++){
      recLead.selectLineItem('item',i);
      recLead.setCurrentLineItemValue('subscriptions','subscribed','T');
      recLead.commitLineItem('item');
    }
    

    Alternatively, if you do not want to do it that way, you can use setLineItemValue, instead.

    var itemCount=recLead.getLineItemCount('subscriptions');
      for(var i=1;i<=itemCount;i++){
      recLead.setLineItemValue('subscriptions','subscribed',i,'T');
    }
    

    Both, effectively, work the same.

    BTW, since you have to start at row 1, you need to make sure you use i<=itemCount. Otherwise, if there are 10 rows, you will miss the last row. When you move to 2.0, and start your count at 0, you can use i< itemCount.