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

Lindsay,



No, I actually didn't run into issues like that. I ran into a ton, but not that! Sorry I can't help you. Travis Toulson is incredibly knowledgeable with this and hopefully he can help you.



Thanks!


Hi Lindsey,



Can you share the exact script you are using?   I think I may know the cause of #1.  



The script checks top.document.referrer which will work as long as the top level frame doesn't change.   ServiceNow operates with 3 main iframe embedded within a site, as you navigate, the iframes change but the top frame does not.   When you click the reference magnifying glass, it opens up a new page with a new top frame that was not referred by the CMS.



I'm not sure on #2 though.   If you can provide your script, Ill try to set it up in my dev to troubleshoot.



Kind regards,



Travis


Hi Travis,


Thanks for getting back to me. Below is the global UI script I am using. I changed it since I've posted and it has resolved #2 but #1 is still an issue, so any insight you can provide would be greatly appreciated.



Event.observe(window, 'load', 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()) {  
    if (document.URL.indexOf('itserviceportal') == -1)
    {
                  // Redirect to ESS  
                  window.location = 'https://instance.service-now.com/itserviceportal/navpage.do';  
        }  
  }
// 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('itil')) {
  if (document.URL.indexOf('itserviceportal') == -1 && top.document.referrer.indexOf('itserviceportal') == -1)
  {  
                  // Redirect to ESS  
                  window.location = 'https://instance.service-now.com/itserviceportal/navpage.do';  
        }
}



       
});  



Thanks,


Lindsey


Hi Lindsey,



Lets try this approach:



Event.observe(window, 'load', 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()) {


  if (document.URL.indexOf('itserviceportal') == -1)


  {


  // Redirect to ESS


  window.location = 'https://instance.service-now.com/itserviceportal/navpage.do';


  }


  }


  // 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('itil')) {


  if ($(gsft_banner) && top.document.referrer.indexOf('itserviceportal') == -1)


  {


  // Redirect to ESS


  window.location = 'https://instance.service-now.com/itserviceportal/navpage.do';


  }


  }


});



You will note my change on line 15 $(gsft_banner).   Originally that script was verifying that we were not on the CMS site.   Instead, I have made the check more specific.   The gsft_banner is the id of the top banner frame in the main ServiceNow window.   If that div exists, then you know that you are not on one of the pop up windows and that you are not on the CMS.   Following that up with the referrer check and you should get a redirect only if you have just initially loaded ServiceNow, you are an itil user, and you were not referred from the CMS.



Kind regards,



Travis


Looking at the first few tests this looks like it solves the issue. Thanks Travis!