Redirect Users with SuiteScript

The SuiteScript API provides methods you can use to redirect users within NetSuite. Those methods are:

The following information and example are specific to the nlapiSetRedirectURL() method available with SuiteScript 1.0.

If you are implementing SuiteCommerce Advanced, you have access to the source code and can search for nlapiSetRedirectURL() to see that this method is used throughout the SSP code. A simple example is in logOut.ssp, which is the logout touch point, and is the SSP file that is called when a user should be logged out. If you want to change where users are directed when they log out, this is where you can set it. A basic example could be:

          return nlapiSetRedirectURL('EXTERNAL', 'https://www.netsuite.com'); 

        

Change the Exit Page after Logging Out

For this example, when a customer logs out, you want to redirect them to a special page that displays a thank you message and tries to re-engage them with promotional products or an invitation to subscribe to your newsletter. The following steps show you how to do this.

  1. Create your re-engagement page.

    How you create the page and the content you include in it is up to you. If you want to create the page quickly, you can use Site Management Tools (SMT) to create it as a landing page and set the URL path to: /come-back-soon. Be sure to use SMT to publish the page. For more information, see Site Management Tools Overview.

  2. Create an extension that includes a copy of logOut.ssp to override the existing file. For more information about creating an extension to override a file, see Patch Using Override Mode.

    Change the content of the logOut.ssp file as shown in the following example:

                    <%
        var session = require('SC.Models.Init').session;
        var touchpoints = session.getSiteSettings(['touchpoints']);
        var home = touchpoints.touchpoints.home;
        var fragment = 'fragment=/come-back-soon&logoff=T'; // a nuance of logOut.ssp is that we must attach this additional parameter to the end
        var redirectUrl = home + (~home.indexOf('?') ? '&' : '?') + fragment;
    
        return nlapiSetRedirectURL('EXTERNAL', redirectUrl);
    %> 
    
                  

    The preceding code example gets the home touch point, attaches the URL path for the re-engagement page to the end of the touch point (along with a required URL parameter), and then returns the redirect URL.

    This method is used throughout SCA source code. For example, in shopping.ssp there is a condition that determines if the site is configured to be password protected and, if it is, the site redirects the user to the login page before loading the shopping SPA (unless the user is already logged in).

Related Topics

URL Routing in Commerce Websites
NetSuite Domain-Level Redirects
URL Routing and Single-Page Applications
Traverse Touch Points
Redirect a User After Login

General Notices