Create a Custom Function to Call a Suitelet

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

The following client script defines a callSuitelet function that sends a request to a Suitelet using the https.requestSuitelet(options) method. The response from the Suitelet is then shown in an alert dialog using the dialog.alert(options) method. To use this script, replace the Suitelet script and deployment IDs with your own values.

          /**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 */

// This script defines a custom function to call a Suitelet.
define(['N/https', 'N/ui/dialog'],
 
    function(https, dialog) {
        function pageInit(scriptContext) {}

        // Create a custom function that calls a Suitelet and displays the response in a dialog
        function callSuitelet() {
            const response = https.requestSuitelet({
                scriptId: 'customscript_sl_plf_requestsuitelet', // Replace with your Suitelet script ID
                deploymentId: 'customdeploy_sl_plf_requestsuitelet', // Replace with your Suitelet deployment ID
            });
            dialog.alert({
                title: 'Suitelet Response',
                message: response.body
            });
        }
     
        return {
            pageInit: pageInit,
            callSuitelet: callSuitelet
        };
         
    }); 

        

General Notices