How to add custom discount amount in sales order form when order is placed with help of client script

Adding custom discount amount in sales order form when order is placed with help of client script in netsuite

  1. First login to netsuite account
  2. Navigate to Customization > Scripting >script >new
  3. add your script file in it and deploy it

The example of client script for sales order form update is as given below

/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 */
define(['N/record', 'N/runtime', 'N/error', 'N/search', 'N/log'],
    /**
     * @param {runtime} runtime
     * @param {url} url
     */
    function(record,runtime,error,search, log){
        function saveRecord(context) {
            try {
                var currentRecord = context.currentRecord;
                var custBodyDiscount = currentRecord.getValue({
                    fieldId: 'custbody_discount_amount'
                });
                if (parseFloat(custBodyDiscount) > 0) {
                    currentRecord.setValue({
                        fieldId: 'discountitem',
                        value: '-6'
                    });
                   log.debug('entity @ Reward Points',  'line 24');
                    currentRecord.setValue({
                        fieldId: 'discountrate',
                        value: ('-' + parseFloat(custBodyDiscount))
                    });
                   log.debug('entity @ Reward Points',  'line 29');
                   currentRecord.setValue({
                        fieldId: 'discounttotal',
                        value: ('-' + parseFloat(custBodyDiscount))
                    });
                   log.debug('entity @ Reward Points',  'line 34');
                  
                  customerRecord.save({ enableSourcing: true, ignoreMandatoryFields: true});
                  log.debug('customer', customerID, totalAmount );
               }
              log.debug('customer', 'end of If' );
            } catch (error) {
                log.debug('Error @ Reward Points', error);
            }
            return true;
        }
        return{
            saveRecord: saveRecord
        }
    }
)

Leave a comment

Your email address will not be published. Required fields are marked *