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

Travis,



As per my morning meeting, this is something that I will pursue. I will probably dive into this tomorrow and will most likely need your assistance.



Thank you again for all your help.


I added the 'if((document.referrer...' to line 21. I haven't tested because I am thinking that's not even right. Should I add it within the if statement of line 18?



As far as scenario 2, that would probably be within the if statement of line 13?



Or, should these 2 scenarios be a separate function?



addLoadEvent(function() {



  try{



  var thisHost = window.location.origin;


  if (!thisHost)


  thisHost = window.location.protocol+"//"+window.location.host;



  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';


  }else if((document.referrer.indexOf('ess')!=-1 || document.referrer.indexOf('navpage.do')!=-1))


  window.location = thisHost + '/ess';


  }


  catch (err) {


  }


});


Actually, for Scenario 1, you can just append it to the else if on line 18 as I have done below.   That way, if they were referred from the ess site link OR email/direct url link, that rule will be ignored and they will not be redirected to ESS (the unwritten/hidden 'else' case of the script causes no redirection / no action).



For Scenario 2, yes, you would add the if logic within the else if statement on line 13.   The basic logic is:



  1. If user is admin, then do not redirect
  2. Else if user is not ESS_IT_User and on a non-ESS page
    1. If the user is on an incident.do page, then redirect to ESS friendly incident page
    2. Else If the user is on a request.do page, then redirect to ESS friendly request page
    3. etc
    4. Else redirect to ESS homepage (the final else, in other words if a suitable ESS page can't be found)
  3. Else if user is a ESS_IT_User and on a non-ESS page and they were not referred by either the ESS site, Email, or direct url link, then redirect to ESS page


There is no need for a separate function in this case because ESS_IT_Users would never redirect to the ESS site if they tried to get to incident.do/sys_id=somesysid for instance.   So only non ESS_IT_Users would use the functionality.   If you had multiple cases using the same incident/request/change routing logic, then it would make sense to use a separate function.



Does that help?



addLoadEvent(function() {  


 


  try{  


 


  var thisHost = window.location.origin;  


  if (!thisHost)  


  thisHost = window.location.protocol+"//"+window.location.host;  


 


  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 OR either email or direct url


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


  // Redirect to ESS  


  window.location = thisHost + '/ess';  


  }


  catch (err) {  


  }  


});  


As a first pass, it doesn't work as it should. I will have to look more into it tomorrow morning.


Travis,



Could you help me understand what lines 17-19 are doing? It seems like the if statement is not correct.