Redirect ITIL users to CMS

Blair5
Tera Guru

We already have login rules in place to redirect non-roled users to our CMS. However, we would like to route all users to the CMS -- how? Also, for itil roled users, we would like to have them click on a link from within the CMS and be routed back to the itil view.

 

For non-roled users, we have a homepage defined for them with a content block that redirects them to the CMS site. We don't want to do that for itil people because we don't want them to be rerouted back to CMS if this click on the link to go to the itil site. Any suggestions?

1 ACCEPTED SOLUTION

Excellent point, yes, if the ITIL user changes their home page, they would bypass your script.   A better alternative is to create it as a global UI Script.   Try this one out:



UI Script



Name: ESS Redirect


Active: True


Description: Redirects users to the ESS site


Global: True


addLoadEvent(function() {


        if (g_user.hasRole('admin') {


                  // Do nothing if user is admin, this is to allow testing of the script without risk


        }


        // If user has no roles and they are on a non ESS page


        else if (!g_user.hasRoles() && document.URL.indexOf('ess') == -1) {


                  // Redirect to ESS


                  window.location = 'https://instancename.service-now.com/ess';


        }


        // If user has roles, they are on a non ESS page and they were not referred from the ess site


        else if (g_user.hasRoles() && document.URL.indexOf('ess') == -1 && top.document.referrer.indexOf('ess') == -1) {


                  // Redirect to ESS


                  window.location = 'https://instancename.service-now.com/ess';


        }


});



NOTE:   Global UI scripts will run on both ITIL site and ESS site.   This is why the document.URL.indexOf('ess') is necessary, it prevents redirection from the ESS site to the Ess site.


View solution in original post

63 REPLIES 63

Excellent point, yes, if the ITIL user changes their home page, they would bypass your script.   A better alternative is to create it as a global UI Script.   Try this one out:



UI Script



Name: ESS Redirect


Active: True


Description: Redirects users to the ESS site


Global: True


addLoadEvent(function() {


        if (g_user.hasRole('admin') {


                  // Do nothing if user is admin, this is to allow testing of the script without risk


        }


        // If user has no roles and they are on a non ESS page


        else if (!g_user.hasRoles() && document.URL.indexOf('ess') == -1) {


                  // Redirect to ESS


                  window.location = 'https://instancename.service-now.com/ess';


        }


        // If user has roles, they are on a non ESS page and they were not referred from the ess site


        else if (g_user.hasRoles() && document.URL.indexOf('ess') == -1 && top.document.referrer.indexOf('ess') == -1) {


                  // Redirect to ESS


                  window.location = 'https://instancename.service-now.com/ess';


        }


});



NOTE:   Global UI scripts will run on both ITIL site and ESS site.   This is why the document.URL.indexOf('ess') is necessary, it prevents redirection from the ESS site to the Ess site.


This is excellent. I'm going to try it right now. What about log in rules or default landing pages? Should I keep them as is?


This worked awesomely! I kept all configurations the same and it's great! I need to tweak the script slightly, but other than that it's great! Thank you thank you thank you!


Not a problem, glad to hear it!   Can you share the tweaks?   That way anyone looking this up in the future can find a completed example?


This is the script with the updates. I wanted to reference the current instance's URL instead of hard coding it. The only issue is, users with out the ESS_IT_User role should stay on the ESS site, otherwise go to ITIL if they click that link. Some users on the ESS site have roles, so I can't use '!g_user.hasRoles()'. By adding these checks, the users are no longer redirected to the ESS page.




var thisHost = gs.getProperty('glide.servlet.uri');



addLoadEvent(function() {


  if (g_user.hasRole('admin')) {


  // Do nothing if user is admin, this is to allow testing of the script without risk


  }


  // If user has no roles and they are on a non ESS page


  else if (!g_user.hasRole('ESS_IT_User') && document.URL.indexOf('ess') == -1) {


  // Redirect to ESS


  window.location = thisHost + '/ess';


  }


  // If user has roles, they are on a non ESS page and they were not referred from the ess site


  else if (g_user.hasRole('ESS_IT_User') && document.URL.indexOf('ess') == -1 && top.document.referrer.indexOf('ess') == -1) {


  // Redirect to ESS


  window.location = thisHost + '/ess';


  }


});