Redirect to ITIL homepage using SPEntryPage

ayman_h
Kilo Sage
Kilo Sage

Hi,

I am having issues when users login using side_door.do. They are redirected to the ITIL homepage (nav_to.do?uri=/side_door.do) and the homepage contains a Page not found error as I am already logged in. To resolve this error I am trying to re-direct users to Welcome.do or home.do instead using the SPEntryPage script (getFirstPageURL). However, when I try to return "/nav_to.do?uri=/home.do", I get a browser error saying there has been too many redirects.

If on the script, I return other pages such as /welcome.do, I am just redirected to the page without the Application Navigator and Banner frame.

Does anyone have an idea how I could redirect to the ITIL homepage with the main frame containing either welcome.do or home.do?

Here is a quick snippet of the getFirstPageURL method inside SPEntryPage, I have highlighted the code in red which I am trying to fix.

getFirstPageURL: function() {

var session = gs.getSession();

this.logProperties('before', session);

gs.log("SPEntryPage Logs getFirstPage");

// 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.hasRole('admin')) && !redirectURL && !isServicePortalURL)

return;

if (user.hasRole('itil') && !redirectURL && !isServicePortalURL){

return "/nav_to.do?uri=/home.do";

}

// 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

if (nt) {

var ep = gs.getProperty("glide.login.home");

if (ep == nt)

nt = null;

}

session.putProperty("login_redirect", nt || "true");

gs.log("SPEntryPage Logs getFirstPage NT: "+nt);

return "/login_redirect.do?sysparm_stack=no";

}

session.clearProperty("login_redirect");

var returnUrl = this.portal;

if (redirectURL && redirectURL != "true") {

var spUrl = new GlideSPScriptable().mapUrlToSPUrl(redirectURL);

returnUrl = spUrl ? this.portal + "?" + spUrl : redirectURL;

}

this.logProperties('after', session);

return returnUrl;

},

logProperties: function(beforeOrAfter, session) {

if (!this.logVariables)

return;

},

1 ACCEPTED SOLUTION

Hey,


Yes, I did solve it in the end, I had an OnLoad UI Script, which was interfering with this script. I have also replaced the code in red, with just 'return;' instead of returning a specific URI. What issue are you currently facing?


View solution in original post

10 REPLIES 10

henry_cheng
ServiceNow Employee
ServiceNow Employee

Hi Ayman,



Can you try to login from URL "https://<instance_name>.service-now.com/navpage.do" to see if you get any page error on the ITIL home page?


If so then something wrong with your homepage and not relevant to login.


In your script include if you want user has a 'itil' role to navigate to the homepage.do after login then you just need to modify the line to below.



if (user.hasRole('itil') && !redirectURL && !isServicePortalURL)


        return;



You don't need to add any return value after the return keyword.



Cheers


Henry


Hi Henry,



Thanks for your reply. I have implemented the getLoginURL method inside the SPEntryPage to redirect users to our Portal page when they hit any pages other than the side door. If I navigate to the https://<instance_name>.service-now.com/navpage.do without having logged in, I have redirected https://<instance_name>.service-now.com/sp/



Here is the code for the getLoginURL



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"));



        if(sPage != "side_door.do?"){


                  return this.portal;


        }


},




Thanks,


Ayman


I'm having the same issue- did you ever solve this?


Hey,


Yes, I did solve it in the end, I had an OnLoad UI Script, which was interfering with this script. I have also replaced the code in red, with just 'return;' instead of returning a specific URI. What issue are you currently facing?