title: NetSuite Get Description and Set Tax during Onchange "Line Items"
body: <p>I am learning NetSuite,</p>
  <p>The scenario I am trying to archive,
  In an Invoice, When adding the line items, if the item description contains &quot;non JP&quot; then add tax value &quot;193&quot; else other tax.</p>
  <p>My Question:</p>
  <p>How to fetch the description of line item when the user select it or change the description.</p>
  <p>I am trying to do custom function:</p>
  <p><strong>The function will execute on : &quot; POST SOURCING FUNCTION&quot;</strong></p>
  <p>My code</p>
  <pre><code>if(scriptContext.sublistId == 'item' &amp;&amp; subsidiary_id == 6){
                   var inv_type = objRecord.getText({fieldId:'custbody3'});
                   var inv_val;
                   for(var i=0;i&lt;inv_type.length;i++){
                   val = inv_type[i];
                   log.debug({
              title: 'inv_type', 
              details: inv_type[i]
          });
                   console.log('inv_type',inv_type);
                   //inv_type = 'Service' || 'Subscription'
                  if(inv_type[i] == 'Services');
              {
  
   var description=&quot;&quot;;
                //////If the Description contains Non JP set Tax Rate = 0
                if(description.contains(&quot;non JP&quot;))
                  {
                     objRecord.setCurrentSublistValue({
                          sublistId: 'item',
                          fieldId: 'taxcode',
                          value: 193,
                          ignoreFieldChange: true,
                          enableSourcing: true
                      });
                  }
                //////If the Description contains Non JP set Tax Rate = 10
               if(description.contains(&quot;JP&quot;))
                  {
                      objRecord.setCurrentSublistValue({
                          sublistId: 'item',
                          fieldId: 'taxrate1',
                          value: 7,
                          ignoreFieldChange: true,
                          enableSourcing: true
                      });
                  }
                  }
              }
                  }
  </code></pre>
  <p>My full script code</p>
  <pre><code>/**
   * @NApiVersion 2.x
   * @NScriptType ClientScript
   * @NModuleScope SameAccount
   */
  define(['N/record', 'N/log'],
      /**
       * @param {record} record
       */
      function (record, log) {
          /**
           * Defines the function that is executed after a sublist is inserted, removed, or edited.
           *
           * @param {Object} scriptContext
           * @param {Record} scriptContext.currentRecord - Current form record
           * @param {string} scriptContext.sublistId - 
           * @since 2015.2
           */
          function postSourcing(scriptContext) {
              try {
                  var objRecord = scriptContext.currentRecord;
                  var subsidiary_id = objRecord.getValue({fieldId:'subsidiary'});
                  
                  //Tax Calculation for China Subsidiary
                  if(scriptContext.sublistId == 'item' &amp;&amp; subsidiary_id == 5){
                   var inv_type = objRecord.getText({fieldId:'custbody3'});
                   var inv_val;
                   for(var i=0;i&lt;inv_type.length;i++){
                   val = inv_type[i];
                   log.debug({
              title: 'inv_type', 
              details: inv_type[i]
          });
                   console.log('inv_type',inv_type);
                   //inv_type = 'Service' || 'Subscription'
                  if(inv_type[i] == 'Services' || inv_type[i] == 'Subscription' || (inv_type[i] == 'Subscription' &amp;&amp; (inv_type[i] =='Expenses' || inv_type[i] == 'Customer Summit Sponsor Fees')) || (inv_type[i] == 'Services' &amp;&amp; (inv_type[i] == 'Expenses' || inv_type[i] == 'Customer Summit Sponsor Fees')) || (inv_type[i] == 'Services' &amp;&amp; inv_type[i] == 'Expenses' &amp;&amp; inv_type[i] == 'Customer Summit Sponsor Fees') || (inv_type[i] == 'Services' &amp;&amp; inv_type[i] == 'Expenses' &amp;&amp; inv_type[i] == 'Customer Summit Sponsor Fees' &amp;&amp; inv_type[i] == 'Subscription' ) || (inv_type[i] == 'Subscription' &amp;&amp; inv_type[i] == 'Expenses' &amp;&amp; inv_type[i] == 'Customer Summit Sponsor Fees')){
                  log.debug({title: 'inv_type1', details: inv_type[i]});
              
                      objRecord.setCurrentSublistValue({
                          sublistId: 'item',
                          fieldId: 'taxcode',
                          value: 52,
                          ignoreFieldChange: true,
                          enableSourcing: true
                      });
                      objRecord.setCurrentSublistValue({
                          sublistId: 'item',
                          fieldId: 'taxrate1',
                          value: 6,
                          ignoreFieldChange: true,
                          enableSourcing: true
                      });
  //                    objRecord.commitLine('item');
                  }
                  if(inv_type[i] == 'Expenses' || inv_type[i] == 'Customer Summit Sponsor Fees') {
                  
                  log.debug({title: 'inv_type1', details: inv_type[i]});
              
                      objRecord.setCurrentSublistValue({
                          sublistId: 'item',
                          fieldId: 'taxcode',
                          value: 51,
                          ignoreFieldChange: true,
                          enableSourcing: true
                      });
                      objRecord.setCurrentSublistValue({
                          sublistId: 'item',
                          fieldId: 'taxrate1',
                          value: 0,
                          ignoreFieldChange: true,
                          enableSourcing: true
                      });
  //                    objRecord.commitLine('item');
                  }
              }
                  }
                  
                  //Tax Calculation for Singapore Subsidiary
                  
                  if(scriptContext.sublistId == 'item' &amp;&amp; subsidiary_id == 69){
                   var inv_type = objRecord.getText({fieldId:'custbody3'});
                   var inv_val;
                   for(var i=0;i&lt;inv_type.length;i++){
                   val = inv_type[i];
                   log.debug({
              title: 'inv_type', 
              details: inv_type[i]
          });
                   console.log('inv_type',inv_type);
                   //inv_type = 'Service' || 'Subscription'
                  if(inv_type[i] == 'Services' || (inv_type[i] == 'Subscription' &amp;&amp; (inv_type[i] =='Expenses' || inv_type[i] == 'Customer Summit Sponsor Fees')) || (inv_type[i] == 'Services' &amp;&amp; (inv_type[i] == 'Expenses' || inv_type[i] == 'Customer Summit Sponsor Fees')) || (inv_type[i] == 'Services' &amp;&amp; inv_type[i] == 'Expenses' &amp;&amp; inv_type[i] == 'Customer Summit Sponsor Fees') || (inv_type[i] == 'Services' &amp;&amp; inv_type[i] == 'Expenses' &amp;&amp; inv_type[i] == 'Customer Summit Sponsor Fees' &amp;&amp; inv_type[i] == 'Subscription' ) || (inv_type[i] == 'Subscription' &amp;&amp; inv_type[i] == 'Expenses' &amp;&amp; inv_type[i] == 'Customer Summit Sponsor Fees')){
                  log.debug({title: 'inv_type1', details: inv_type[i]});
              
                      objRecord.setCurrentSublistValue({
                          sublistId: 'item',
                          fieldId: 'taxcode',
                          value: 193,
                          ignoreFieldChange: true,
                          enableSourcing: true
                      });
                      objRecord.setCurrentSublistValue({
                          sublistId: 'item',
                          fieldId: 'taxrate1',
                          value: 7,
                          ignoreFieldChange: true,
                          enableSourcing: true
                      });
  //                    objRecord.commitLine('item');
                  }
                  if(inv_type[i] == 'Expenses' || inv_type[i] == 'Customer Summit Sponsor Fees' || inv_type[i] == 'Subscription' ) {
                  
                  log.debug({title: 'inv_type1', details: inv_type[i]});
              
                      objRecord.setCurrentSublistValue({
                          sublistId: 'item',
                          fieldId: 'taxcode',
                          value: 192,
                          ignoreFieldChange: true,
                          enableSourcing: true
                      });
                      objRecord.setCurrentSublistValue({
                          sublistId: 'item',
                          fieldId: 'taxrate1',
                          value: 0,
                          ignoreFieldChange: true,
                          enableSourcing: true
                      });
  //                    objRecord.commitLine('item');
                  }
              }
                  }
                
                
                
                
                
                //////////////////////Tax calculation for subsidiary 'Japan'
                      
                  
                  if(scriptContext.sublistId == 'item' &amp;&amp; subsidiary_id == 6){
                   var inv_type = objRecord.getText({fieldId:'custbody3'});
                   var inv_val;
                   for(var i=0;i&lt;inv_type.length;i++){
                   val = inv_type[i];
                   log.debug({
              title: 'inv_type', 
              details: inv_type[i]
          });
                   console.log('inv_type',inv_type);
                   //inv_type = 'Service' || 'Subscription'
                  if(inv_type[i] == 'Services');
              {
  
   var description=&quot;&quot;;
                //////If the Description contains Non JP set Tax Rate = 0
                if(description.contains(&quot;non JP&quot;))
                  {
                     objRecord.setCurrentSublistValue({
                          sublistId: 'item',
                          fieldId: 'taxcode',
                          value: 193,
                          ignoreFieldChange: true,
                          enableSourcing: true
                      });
                  }
                //////If the Description contains Non JP set Tax Rate = 10
               if(description.contains(&quot;JP&quot;))
                  {
                      objRecord.setCurrentSublistValue({
                          sublistId: 'item',
                          fieldId: 'taxrate1',
                          value: 7,
                          ignoreFieldChange: true,
                          enableSourcing: true
                      });
                  }
                  }
              }
                  }
                /////////////////////////////////////End
             
                  
                  
                  return true;
              } catch (e) {
                  console.log(&quot;Error in validateLine : &quot; + e);
                  log.error('Error in validateLine', e);
              }
          }
  
          return {
              postSourcing: postSourcing
          };
  
      });
  </code></pre>
  <p>Other functionality works fine,</p>
  <p>I need to get description  for line items only in section Japan (Added in comments) and set the tax based on the description.</p>