Hide Buttons from record using JQuery

Description

User event script with JQuery to hide the unwanted buttons from the task record.

Jira Code : HGPLA – 209

/**
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
 */

define(['N/record', 'N/ui/serverWidget'],
    /**
 * @param{record} record
 */
    (record, serverWidget) => {
        /**
         * Defines the function definition that is executed before record is loaded.
         * @param {Object} scriptContext
         * @param {Record} scriptContext.newRecord - New record
         * @param {string} scriptContext.type - Trigger type; use values from the context.UserEventType enum
         * @param {Form} scriptContext.form - Current form
         * @param {ServletRequest} scriptContext.request - HTTP request information sent from the browser for a client action only.
         * @since 2015.2
         */
        const beforeLoad = (scriptContext) =>
        {
            try
            {
                if( scriptContext.type == 'edit' || scriptContext.type == 'view' )
                {
                    let hideFld = scriptContext.form.addField({
                        id: 'custpage_hide_buttons',
                        label: 'not shown - hidden',
                        type: serverWidget.FieldType.INLINEHTML
                    });
                    let scr = "";

                    //Hiding the Attach button under Escalation
                    scr += 'jQuery("#attach.rndbuttoninpt").hide();';
                    scr += 'jQuery("#tr_attach.tabBnt").hide();';

                    //Hiding the Customise View button in View mode
                    scr += 'jQuery("#customize.rndbuttoninpt").hide();';
                    scr += 'jQuery("#tr_customize.tabBnt").hide();';

                    /** === SANDBOX === **/
                    //Hiding the New Escalate To  button in View mode - SB
                    scr += 'jQuery("#tdbody_newrecrecmachcustrecord_jj_link_parent").hide();';
                    scr += 'jQuery("#tr_newrecrecmachcustrecord_jj_link_parent").hide();';

                    //Hiding the New Escalate To  button in Edit mode - SB
                    scr += 'jQuery("#newrec1237.rndbuttoninpt").hide();';
                    scr += 'jQuery("#tr_newrec1237.tabBnt").hide();';

                    /**  ===== PRODUCTION ===== **/

                    //Hiding the New Escalate To button in Edit mode - Production
                    scr += 'jQuery("#newrec1505.rndbuttoninpt").hide();';
                    scr += 'jQuery("#tr_newrec1505.tabBnt").hide();';

                    //Hiding the New Escalate To  button in View mode -Production
                    scr += 'jQuery("#newrecrecmachcustrecord_jj_parent_link_escalate.rndbuttoninpt").hide();';
                    scr += 'jQuery("#tr_newrecrecmachcustrecord_jj_parent_link_escalate.tabBnt").hide();';


                    hideFld.defaultValue = "<script>jQuery(function($){require([], function(){" + scr + ";})})</script>";

              }
            }
            catch (e)
            {
                log.debug("Error @ beforeLoad", e );
            }
        }

        return { beforeLoad }

    });

Leave a comment

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