How to Hide Subtabs Inside a NetSuite Record using suiteScript?

We can use an inline HTML field and jQuery to hide the subtab using a user event script.

Sample code: It hides the communication subtab for specific roles

/**
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
 */
define(['N/ui/serverWidget', 'N/runtime'],
    /**
 * @param{serverWidget} serverWidget
 */
    (serverWidget, runtime) => {
        /**
         * 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 !== scriptContext.UserEventType.VIEW && scriptContext.type !== scriptContext.UserEventType.EDIT) return;


                var form = scriptContext.form;
                var userRole = runtime.getCurrentUser().role;
                var rec = scriptContext.newRecord;
                log.debug('userRole', userRole);


                // Example: Only hide subtabs for non-admin users
                if (userRole == 3) {
                    var htmlField = form.addField({
                        id: 'custpage_hide_billing_subtab',
                        type: serverWidget.FieldType.INLINEHTML,
                        label: 'Hide Billing Subtab'
                    });

                    // Inject jQuery + DOM manipulation script
                    htmlField.defaultValue = `
                <script>
                    jQuery(document).ready(function() {
                         jQuery('#cmmnctntablnk').hide();
                   });
                </script>
            `;
                }
            } catch (e) {
                log.error('error@beforeload', e);
            }
        }


        return { beforeLoad}


    });

Leave a comment

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