How to Use response.sendRedirect in NetSuite SuiteScript

How to Use `response.sendRedirect` in NetSuite SuiteScript

Overview:

In NetSuite SuiteScript, the `response.sendRedirect` function allows developers to redirect users to a specific page, record, or script within NetSuite. This is particularly useful when you want to guide users to a different location after they perform certain actions in a Suitelet or RESTlet.

Syntax:

javascript

response.sendRedirect({

  type: redirect.Type, // The type of the redirect (e.g., RECORD, TASKLINK, SUITELET, etc.)

  identifier: string, // The internal ID of the record, script, or task link being redirected to

  id: string,     // The internal ID of the record to redirect to (only used when type is RECORD)

  parameters: Object  // An optional object of query string parameters to append to the URL

});

Parameters:

– type: Specifies the type of redirect. Common types include `RECORD`, `TASKLINK`, `SUITELET`, etc.

– identifier: The internal ID or script ID of the entity to which you are redirecting.

– id: (Optional) Used when the type is `RECORD`; this is the internal ID of the record you want to redirect to.

– parameters: (Optional) An object containing query string parameters that will be appended to the URL.

Examples:

1. Redirect to a Record:

To redirect a user to a specific customer record, use the following code:

response.sendRedirect({

  type: redirect.Type.RECORD,

  identifier: ‘customer’,

  id: ‘1234’, // Replace with the internal ID of the customer record

  parameters: {

    ‘customparam’: ‘value’ // Optional parameters

  }

});

2. Redirect to a Suitelet:

To redirect to a Suitelet script, use this code snippet:

response.sendRedirect({

  type: redirect.Type.SUITELET,

  identifier: ‘customscript_my_suitelet’, // Replace with your Suitelet script ID

  id: ‘customdeploy_my_deployment’, // Replace with your Suitelet deployment ID

  parameters: {

    ‘custparam1’: ‘value1’, // Optional parameters

    ‘custparam2’: ‘value2’

  }

});

Usage Notes:

– Always ensure that the `type`, `identifier`, and `id` (if applicable) are correctly set to avoid errors.

– The `parameters` object is optional but useful for passing additional data to the redirected page or script.

– When redirecting to records or Suitelets, ensure the user has the necessary permissions to view the redirected page.

By using `response.sendRedirect`, you can effectively control user navigation and enhance the user experience within your NetSuite implementation.

Leave a comment

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