Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

this is not working

Travis,



I think I'm going to go with this solution. We are going to add the content block to all out of box homepages.



I created the content block with this script:



<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


<span id="redirect_message"><a style="align:right; color:blue" href=".." target="top">Redirect to Default UI</a></span>


  <script>




try{


  var len = top.location.href.indexOf(".com") + 4;


  var base = top.location.href.substring(0,len);


  var thisHost = window.location.origin;



  if (top.document.referrer != thisHost + '/ess') {


  window.location.href = thisHost + '/ess';


  }


      }


  catch (err) {



                    }


  </script>


</j:jelly>



It's not allowing the user to go back to the ITIL site.


Joe Wilmoth
ServiceNow Employee
ServiceNow Employee

Hi Blair,



There are many ways to go about redirecting users. I would try to stay away from Global UI Scripts, they can create issues in other areas of the system that may not be noticed at the present time.



Have you had a look at this wiki article? http://wiki.servicenow.com/index.php?title=Login_Scenarios#gsc.tab=0



Take a look at the article and let me know if that helps you at all.



Thank you,


poojasingh
Giga Contributor

Hi Travis,



This UI Script is working on the login page as well.


But currently when the user goes to the login page, this UI scripts lands him to a different Page.



The condition gs.hasRole('admin') is not working properly on the login page which is expected since no session has been established.



Is there a way that we can call this script only after the user has logged in?


Hi Pooja,



You might be able to wrap an extra "if" statement around the script to test what page you are on.   Something like this:



if (window.top.location.href.indexOf('login.do') != -1) {


    // Check user roles and redirect if necessary


}



That way you can exclude any pages where there is a problem.   There may be a better way to identify when the user is not logged in and I remember looking into this before but sadly I can't find my notes on how I solved this before.   X_X