Directly Triggering Suitelets on Button Click in NetSuite (Without Client Scripts)

1. Overview

In NetSuite, Suitelets can be executed by clicking a button on a record. While a Client Script is commonly used to handle button actions, it’s possible to simplify this process by configuring the button to directly open a Suitelet URL. This approach minimizes additional script dependencies and can streamline Suitelet execution in simpler use cases.

2. Key Concepts for Directly Triggering Suitelets

  • Suitelet URL Configuration: Suitelets have unique URLs that can be constructed using NetSuite’s format, enabling direct access via a button.
  • URL Manipulation: Passing parameters within the URL allows Suitelets to receive relevant data from the record without needing a Client Script.
  • Inline HTML Method: By embedding HTML directly in the button’s label or creating a clickable link, users can trigger the Suitelet directly.

3. Steps to Call a Suitelet on Button Click Without a Client Script

Step 1: Create the Suitelet

Write the Suitelet to perform the desired action. Ensure it can handle any URL parameters needed, as these will be passed directly in the URL from the button.

/**

 * @NApiVersion 2.1

 * @NScriptType Suitelet

 */

define([‘N/log’, ‘N/record’, ‘N/ui/serverWidget’],

  function(log, record, serverWidget) {

    function onRequest(context) {

      if (context.request.method === ‘GET’) {

        const recordId = context.request.parameters.recordId;

        log.debug(‘Received Record ID:’, recordId);

         

        // Add logic for Suitelet processing

        // Example: Load record and log some details

         

        const rec = record.load({ type: ‘customrecord_type’, id: recordId });

        log.debug(‘Loaded Record:’, rec);

         

        // Send a response or redirect

        context.response.write(‘Suitelet executed successfully!’);

      }

    }

    return { onRequest };

  }

);

Step 2: Generate the Suitelet URL

To construct the URL, go to Customization > Scripting > Script Deployments, find your Suitelet deployment, and copy its External URL. This URL will serve as the base link for the button.

Example URL format:

https://[accountID].app.netsuite.com/app/site/hosting/scriptlet.nl?script=[scriptID]&deploy=[deployID]

Step 3: Add the Button to Your Record

Navigate to the desired custom record or standard record customization and add a custom button. In the button’s setup, embed the Suitelet URL directly in the button configuration, passing necessary parameters in the URL.

Example:

https://[accountID].app.netsuite.com/app/site/hosting/scriptlet.nl?script=123&deploy=1&recordId={record.id}

Step 4: Configure the Button on the Record Form

  1. Go to: Customization > Forms > Entry Forms (for custom records) or Transaction Forms (for standard records).
  2. Edit the Form: Locate the Buttons section and add a Custom Button.
  3. Label the Button: Provide a name like “Execute Suitelet.”
  4. Configure the Button Action:
  • Use HTML or script in the onclick attribute:

<button onclick=”window.open(‘https://[accountID].app.netsuite.com/app/site/hosting/scriptlet.nl?script=123&deploy=1&recordId={record.id}’)”>Execute Suitelet</button>

4. Inline HTML Approach

Alternatively, an inline HTML button can be embedded in a custom field to trigger the Suitelet:

  1. Create a Custom Field: Set the field type to Inline HTML.
  2. Insert the Button HTML:

<a href=”https://[accountID].app.netsuite.com/app/site/hosting/scriptlet.nl?script=123&deploy=1&recordId=recordId” target=”_blank”>

  <button>Run Suitelet</button>

</a>

5. Considerations and Limitations

  • URL Parameters: Ensure parameters like recordId are dynamically populated when building the URL in HTML or Suitelet.
  • Permissions: Verify that users have permissions to access and run the Suitelet.
  • Security: Avoid exposing sensitive data in the URL.
  • Limited Interactivity: This approach is best for Suitelets that don’t require complex user interactions since it lacks dynamic client-side handling that Client Scripts provide.

Conclusion

Calling a Suitelet from a button click without a Client Script is efficient for straightforward processes that don’t require dynamic interaction. This technique streamlines Suitelet execution by leveraging NetSuite’s custom buttons and inline HTML, reducing script complexity and improving execution speed.

Leave a comment

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