Add a Button that Calls a Custom Function

This script is part of a multi-script sample. For the complete code sample, see Call a Suitelet from a Client Script.

The following user event script adds a button to a form. When the button is clicked, it calls the callSuitelet function that is defined in the referenced client script. The Form.clientScriptModulePath property is used to specify the path to the client script where the custom function is defined. Ensure that you replace the value with the path to your client script.

Note:

This script sample uses the define function, which is required for an entry point script (a script you attach to a script record and deploy). You must use the require function if you want to copy the script into the SuiteScript Debugger and test it. For more information, see SuiteScript 2.x Global Objects.

Important:

This sample uses SuiteScript 2.1. For more information, see SuiteScript 2.1.

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

// This script adds a button to a form and calls a custom function defined in a client script.
define(['N/ui/serverWidget'], 
    
    function (serverWidget) {
        function beforeLoad(scriptContext) {
 
            // Add a button that calls the callSuitelet function
            scriptContext.form.addButton({
                id: 'custpage_call_suitelet_button',
                label: 'Click to Open Suitelet',
                functionName: 'callSuitelet'
            })
             
            // Specify the path to the client script where the callSuitelet function is defined
            scriptContext.form.clientScriptModulePath = './cs_request_suitelet.js' // Replace with the path to your client script
        }

        return {beforeLoad} 
    }); 

        

General Notices