0 Replies Latest reply on Feb 11, 2020 8:04 PM by Eric.Anderson3

    help understanding record.save()


      We use a hosting platform connected to Avalara to take orders and collect the correct tax amounts. Currently our integration pushes the tax rates calculated by Avalara to the sales order record to overwrite the default tax rates with the use tax rates we charged. Sometimes a user may need to edit the sales order and charge a different shipping tax rate. I've created a user event script to update that field when the shipping tax rate override field is changed and it will update the rate, but the tax amount does not recalculate. It won't calculate until the user hits edit again and the amounts update. Is there a way to get the amounts to update within the first firing of this user event script? I've tried this loading the current record and saving it aftersubmit, and setting the value of the context.newRecord without loading it, but neither give the desired result.


      Thank you,


       * @NApiVersion 2.0
       * @NScriptType UserEventScript
      function(record) { 
          function afterSubmit(context) {
              if (context.type === 'edit'){       
                  var objRecord = record.load({
                      type: record.Type.SALES_ORDER,
                      id: context.newRecord.id,
                      isDynamic: true
                  var myShippingTaxRate = objRecord.getValue('custbody_fa_shipping_tax'); //shipping tax rate custom field
                  var myShippingTaxCode = objRecord.getValue('shippingtaxcode');
                  if (myShippingTaxRate && (myShippingTaxCode !== '-7' && myShippingTaxCode !== '-8')){ //check to not push a rate on non-taxable codes
                      objRecord.setValue('shippingtax1rate', myShippingTaxRate);
                      log.debug('new shipping rate', myShippingTaxRate);
          return {
              afterSubmit: afterSubmit