Navigating to a New Suitelet Page from the Current Suitelet Page

Navigating to a new Suitelet page from the current Suitelet page in NetSuite can be achieved using the url.resolveScript function. This function helps generate a URL for another Suitelet, which can then be used for redirection or linking purposes.

Using url.resolveScript

The url.resolveScript function returns an internal or external URL to a Suitelet. This function is part of the SuiteScript 2.x N/url module and is commonly used to dynamically create URLs for Suitelets based on script and deployment IDs.

Parameters for url.resolveScript

  • options.deploymentId: The script ID (string) or internal ID (number) of the deployment script.
  • options.scriptId: The script ID (string) or internal ID (number) of the script. The ID must identify a RESTlet or a Suitelet.
  • options.params: An optional object containing name/value pairs to describe the query parameters.
  • options.returnExternalUrl: An optional boolean indicating whether to return the external URL. Setting this value to true requires that the script is run in a trusted context for authenticated users. By default, the internal URL is returned.

Here is a sample code snippet that demonstrates how to generate a URL for a new Suitelet and navigate to it from the current Suitelet:

/**
 * @NApiVersion 2.x
 * @NScriptType Suitelet
 */
define(['N/ui/serverWidget', 'N/url', 'N/record'], function (serverWidget, url, record) {


    function onRequest(context) {
        if (context.request.method === 'GET') {
            // Create the form
            var form = serverWidget.createForm({
                title: 'Current Suitelet Page'
            });


            // Add a submit button
            form.addSubmitButton({
                label: 'Go to Edit Lead Page'
            });


            context.response.writePage(form);
        } else {
            // Handle POST request to navigate to a new Suitelet page


            var internalId = 12345; // Example internal ID, replace with actual value


            var editUrl = url.resolveScript({
                scriptId: 'customscript_jj_sl_edit_lead_record',
                deploymentId: 'customdeploy1',
                returnExternalUrl: true,
                params: {
                    leadid: internalId
                }
            });


            // Redirect to the new Suitelet page
            context.response.sendRedirect({
                type: serverWidget.FormPageType,
                url: editUrl
            });
        }
    }


    return {
        onRequest: onRequest
    };
});


Leave a comment

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