The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Login Redirect Issues

nluoma
Kilo Sage

We have been using ServiceNow for several years (started on Berlin) and have been using a customized version of the original ess portal up until our upgrade to Yokohama last month and are now moving to the Service Portal (/sp). This means that the non-ITIL users now need to go to a new URL.

We have updated all desktop shortcuts to point to the new /sp site, but after years of using /ess there are saved shortcuts that are still being used. (We have sent out emails telling everyone about the URL change, but users don't always read emails, and often don't realize how shortcuts and bookmarks work.)

I followed the instructions to set up the automatic routing using the SPEntryPage and the different sys properties.  But, the issue is that some users are coming in with an incorrect redirect url. I cannot set it up so ITIL users go to the main interface while all others go to /sp because we have different portals available for some groups (for example, our Kiosk users and our Retail Stores) and cannot ignore a direct request. 

I have added a redirect script to the /ess page, which works for users who are already logged in. The process still sends them to the /ess page, but it then passes them on to the /sp page. (I did remove most of the content on the old /ess page to make this faster.)

However, if a non-ITIL user who is not logged in tries to go to /ess (by using a shortcut or bookmark, for example), the system prompts them to log in and then redirects them to /ess.do which gives them a 404 error. This is not a good result for end users, obviously, so I want get them logged in and going to /sp.

I've looked at the SPEntryPage script, and I'm sure there has to be some way to modify this so that we can redirect only the /ess requests, while still honoring the other portals, but I haven't been able to figure out how to do this.

Does anyone have an idea how I would address this? I've scoured the forums, but can't find anything that applies. There appear to be several approaches if you are moving between the newer Service Portals, but very little on what to do with the old content management portals.

5 REPLIES 5

VikMach
Mega Sage

Hi @nluoma,

Have you tried this new feature that allows all users to be redirected to the alternate portal when a portal is inactivated? 
As I understand you would like all the users to be directed to the new SP portal, you could set the old portal to inactive = true and a new field will show up asking where would you like users to be redirected to. Select the new portal from the list and all users should be then redirected to new portal. See snip below.

Vikas1_0-1747604420078.png


Let me know if this helped!

Regards,
Vikas K

 

This only works for Service Portals--not the old Content Management ESS Portals.
The ESS portals do have an active checkbox, but if I deselect it, it's not processed like the Service Portals are and don't get redirected, instead the users get the 404 error when they use the direct link (this happens for *both* logged in and not logged in users, because the page is never loaded so the redirect I added never gets applied.)

Sebastian L
Mega Sage

Could you paste your current version of SPEntryPage ? 

 

I have in previous versions done a UI Script that handles redirect from the backend to the portal, but this logic should and could be handled in that script include now. 

 

This article explains it quite well, but please post your script so we can look at it : https://www.servicenow.com/community/servicenow-ai-platform-blog/6-ways-to-set-up-your-service-porta... 


Best regards,
Sebastian Laursen

nluoma
Kilo Sage

Currently it is OOB with the only exception being that I turned on the logging. Here it is:

/** 
 *
 *  Service Portal sample script include to indicate 
 *  1. which login page should be used
 *  2. the starting page after the user is authenticated 
 * 
 *  Script is configured using system properties
 
 *  PROPERTY                        VALUE
 *  glide.entry.page.script         new SPEntryPage().getLoginURL(); 
 *  glide.entry.first.page.script   new SPEntryPage().getFirstPageURL();
 * 
 * functions can return a path or null if no overrides are necessary
 * 
 **/
var SPEntryPage = Class.create();

SPEntryPage.prototype = {

    initialize: function() {
        this.logVariables = true; // for debugging 
        this.portal = this.getDefaultPortal(); // The URL suffix for default portal
    },

    /***
     *
     * Fetch the default portal suffix
     *
     **/
    getDefaultPortal: function() {
        var gr = new GlideRecord("sp_portal");
        gr.addQuery("default", true);
        gr.query();
        if (gr.next())
            return "/" + gr.getValue("url_suffix") + "/";

        return "/esc/";
    },
    /***
     *
     * Referred to by property: glide.entry.page.script
     * 
     **/
    getLoginURL: function() {
        // When requesting a page directly (eg: /problem_list.do)
        // The platform session_timeout.do sets the login page to welcome.do
        // Since we are handling the login, clear that value
        var session = gs.getSession();
        var nt = session.getProperty("nav_to");
        var sPage = session.getProperty("starting_page");
        if (nt == "welcome.do")
            session.clearProperty("nav_to");

        if (!sPage && !nt)
            session.putProperty("starting_page", gs.getProperty("glide.login.home"));

        // Send the user to the portal's login page
        var portalGR = new GlideRecord("sp_portal");
        portalGR.addQuery("url_suffix", this.portal.replace(/\//g, ""));
        portalGR.addNotNullQuery("login_page");
        portalGR.query();
        if (portalGR.next())
            return this.portal + "?id=" + portalGR.login_page.id;

        // Send to the a default login page
        return this.portal + "?id=login";
    },

    /***
     *
     * Referred to by property: glide.entry.first.page.script
     * 
     **/
    getFirstPageURL: function() {
        var session = gs.getSession();
        this.logProperties('before', session);

        // has roles and is not a Service Portal page - go to UI16
        var nt = session.getProperty("nav_to");
        var isServicePortalURL = new GlideSPScriptable().isServicePortalURL(nt);
        var redirectURL = session.getProperty("login_redirect");

        if (user.hasRoles() && !redirectURL && !isServicePortalURL)
            return;

        // user may have logged in from a frame, the /login_redirect.do page will bust out of it
        if (!redirectURL) {
            // redirectURL is nav_to 
            // if nav_to == "welcome.do" then use starting_page
            var sPage = session.getProperty("starting_page");
            if (sPage && nt == "welcome.do")
                nt = sPage;

            // Avoid a redirect loop to the home page
            var ep = gs.getProperty("glide.login.home");
            if (nt) {
                if (ep == nt)
                    nt = null;
            }
            // PRB726860: if page is still welcome.do, go to glide.login.home preserving frameset
            if (nt == "welcome.do") {
                session.putProperty("nav_to", ep);
                return;
            }

            session.putProperty("login_redirect", nt || "true");
            return "/login_redirect.do?sysparm_stack=no";
        }

        session.clearProperty("login_redirect");
        session.clearProperty("nav_to");
        if (redirectURL && redirectURL.indexOf("sys_attachment.do") > -1)
            return redirectURL;
        var returnUrl = this.portal;
        if (redirectURL && redirectURL != "true") {
            var spUrl = new GlideSPScriptable().mapUrlToSPUrl(redirectURL);
            returnUrl = spUrl ? this.portal + "?" + spUrl : redirectURL;
            if (!user.hasRoles() && !spUrl && redirectURL.indexOf("home_splash.do") > -1)
				returnUrl = this.portal;
        }

        this.logProperties('after', session);
        if (!this.logVariables) {
            gs.log('redirectURL: ' + redirectURL);
            gs.log('User: ' + user.getName());
            gs.log('is internal: ' + (!user.hasRoles()));
            gs.log('returnUrl: ' + returnUrl);
        }

        return returnUrl;
    },

    logProperties: function(beforeOrAfter, session) {
        if (!this.logVariables)
            return;

        gs.log('SPEntryPage: Redirect ------------------------------- ' + beforeOrAfter);
        gs.log('session.starting_page: ' + session.getProperty("starting_page"));
        gs.log('session.nav_to: ' + session.getProperty("nav_to"));
        gs.log('session.login_redirect: ' + session.getProperty("login_redirect"));
        gs.log('gs.fURI: ' + session.getURI());
    },

    type: 'SPEntryPage'
};