CLIENT SCRIPT SAMPLE TO SET TAX ITEM BASED ON LOCATION

this script sample is to set the tax item in customer based on the custom field and criteria based on locations

/**

 * @NApiVersion 2.1

 * @NScriptType ClientScript

 * @NModuleScope SameAccount

 */

define([‘N/record’],

/**

 * @param{record} record

 */

function(record) {

   

   

    /**

     * Validation function to be executed when field is changed.

     *

     * @param {Object} scriptContext

     * @param {Record} scriptContext.currentRecord – Current form record

     * @param {string} scriptContext.sublistId – Sublist name

     * @param {string} scriptContext.fieldId – Field name

     * @param {number} scriptContext.lineNum – Line number. Will be undefined if not a sublist or matrix field

     * @param {number} scriptContext.columnNum – Line number. Will be undefined if not a matrix field

     *

     * @returns {boolean} Return true if field is valid

     *

     * @since 2015.2

     */

    function validateField(scriptContext) {

        try{

       

        let dataObj = scriptContext.currentRecord;

        let salesOrderType = scriptContext.fieldId;

        if(salesOrderType === ‘custentity_jj_sales_order_type’){

        let salesOrderTypeValue = dataObj.getText({

            fieldId: ‘custentity_jj_sales_order_type’

        })  

        console.log(‘salesOrderTypeValue’,salesOrderTypeValue)    

        if(salesOrderTypeValue === ‘Reseller’ || salesOrderTypeValue === ‘Non Profit Organization’)

            {

                dataObj.setValue({

                    fieldId:‘taxitem’,

                    value: 8

                })

               

            }

           

        else if(salesOrderTypeValue === ‘Regular’){

            let shipAddressTrue = dataObj.getText({

                fieldId: ‘defaultshipping’

            })

            let shipAddress = dataObj.getText({

                fieldId: ‘defaultaddress’

            })

            log.debug(‘shipAddressTrue’,shipAddressTrue)

            log.debug(‘shipAddress’,shipAddress)

           

        }

    }

    return true;

    }

    catch(e){

        console.log(‘error@validateField’,e)

    }

    }

   

    return {

       

        validateField: validateField,

       

    };

   

});

Leave a comment

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