0
votes

I am learning netsuite,

I need to get the line item description in invoice module,If the description contains Tax, then I need to change "term" field value to "Taxable term"

How to fetch the "description" of the particular line item and update its "term", if description field value contains "tax"?

Thanks in advance,

1

1 Answers

0
votes

The steps to be followed are as follows:

  1. Get the sublist ID
  2. Get the number of lines present (LineCount)
  3. Use the FOR LOOP to iterate within those lines, and make changes accordingly.
  4. After making the changes, commit the line
  5. Finally, save the record
//Loading the record - Invoice 
var recordInvoice = record.load({
   type: record.Type.INVOICE,
   id: 276
});

So firstly, you will require to fetch the ID of that sublist containing the 'description' field. (In most of the cases its item, I'll go with it).

Next, get the number of lines.

var numLines = record.getLineCount({
 sublistId: 'item'
});

Using FOR Loop, iterate through the lines. Make sure you select the line and use correct syntax

for(var j=0; j<numLines; j++) {

   record.selectLine({
      sublistId: 'item',
      line: j
   )};

   var descriptionValue = record.getCurrentSublistValue({
      sublistId: 'item',
      fieldId: 'description' //Try finding this value using &xml=t
   });

   if(descriptionValue) {

      record.setCurrentSublistValue({
         sublistId: 'item',
         fieldId: 'yourfield',
         value: 'your value'
      });

   }

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

record.save(); 

Try this out, let me know if you face any issues in the comments.