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

Henk5
Tera Contributor

Thanks Travis, I;ll give that a try. Like you said, lots of redirect pages, most of which you cannot control. It's a shame the login rules were made legacy, they did exactly what we needed in this case.


Travis -- any updates to this if you wanted to redirect all uses to Service Portal, but allow itil users to access the console if needed - through a link on the page?


Hi Kim,



These days the world is a better place for controlling redirects.   UI Scripts are basically no longer needed because everything can be done via a Script Include and the glide.entry.first.page.script property.   This property, as far as I am aware, was first made available with Service Portal as a counterpart to the glide.entry.page.script property introduced with CMS.   Here's a quick summary of the properties:



glide.entry.page.script:


A script that is run when a non-authenticated user navigates to any url associated with the ServiceNow instance in order to determine which Login page a user should use.   It can also set the page to which the user is redirected after login using session properties.   See the SPEntryPage.getLoginURL function as a reference.



glide.entry.first.page.script:


A script that is used to determine which page an authenticated user will see when attempting to access the instance externally for the first time.   "First time" is here defined as when a user types a URL directly into the address bar for the instance or clicks a link from an external website.   In other words, modifying this script will allow you to direct ITIL users to the Portal first but allow a link from the Portal to bypass the script and directly navigate to the internal UI.   See SPEntryPage.getFirstPageURL as a reference.



My Recommended Approach


On all newer instances (Helsinki forward I think) I recommend using these properties over any previous documented method for robust navigation control.   The best way to do it is:



1.   Copy the SPEntryPage Script Include (so you still get updates on SPEntryPage in the future)


2.   Modify the copied Script Include to your needs


        WARNING:


        These scripts provide very low level access to the navigation and authentication processes.   Failure to follow these safety precautions could prevent you from accessing your instance.   ServiceNow may be able to fix it but your whole instance will be down until they do.


        - NEVER use nav_to.do in the returned URL's.   Set the nav_to session property if you want to include frames, see SPEntryPage as an example.


        - ALWAYS provide a bypass in the script for admin users to get to the default internal UI.


        - Keep an admin user logged in on a separate browser (Admin on IE, impersonate other user on Chrome for example)


3.   Update the properties above with your new Script Include



That should get you started but if you run into trouble let me know.   I will help as much as I can.   This request has come up so much I'd love to help provide the Holy Grail Redirect but I have to make some time before I can get there 😄



Hope this helps!


This has come at the perfect time! We are just upgrading to the service portal and redirects have ALWAYS been a head ache. Thank you!


I'm just glad I can finally answer your question after 3 years