Script to create a Custom Button in the Customer Record

This script will create a custom button named ‘EMAIL STATEMENT’ in the customer record

/**
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
 */
/*******************************************************************
 *   UserEventScript
 ****************************************************************
 *
 * Date: 07/04/2022
 *
 * Author: Jobin and Jismi IT Services LLP
 *
 * REVISION HISTORY
 *
 * Revision 1.0
 *
 * Description: Script to set button on customer record specifically for MTE subsidiary
 *
 * Revision 2.0
 *
 ***************************************************************/
define(['N/record', 'N/search', 'N/ui/serverWidget'],

    (record, search, serverWidget) => {
        /**
         * @param function before load function creates a button on the customer record of MTE subsidiary.
         */
        const beforeLoad = (scriptContext) => {
            try{
                if (scriptContext.type === 'view'){

                    var recObj = scriptContext.newRecord;

                   // log.debug("customerId",customerId)
                    var findSub=recObj.getValue({fieldId:'subsidiary'});
                    log.debug("findSub",findSub);
                   //  var customer=recObj.getValue({fieldId:'altname'});
                    var customer=scriptContext.newRecord.id;
                    log.debug("customer",customer);
                    var form = scriptContext.form;
                   // log.debug("form",form);
                    if(findSub==3){
                        // log.debug("testing2");
                        scriptContext.form.addButton({id: 'custpage_send', label: 'EMAIL STATEMENT', functionName: 'sendEmail("'+ customer +'")'});
                        var buttonObj = form.getButton({id: 'custpage_send'});
                        log.debug("buttonObj",buttonObj);
                    }
                    scriptContext.form.clientScriptModulePath='/SuiteScripts/JJ CS Cust Button Redirect MAG-424.js';

                }

            }catch (e) {
                log.debug('error@beforeLoad',e);
            }
        }
        return {beforeLoad}
});

Leave a comment

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