- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2014 10:47 AM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2014 07:07 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2014 07:57 AM
Great thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2014 08:04 AM
Do you see any issue with my script? Because it isn't redirecting users to ESS anymore
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2014 08:42 AM
Yes, the problem is in line 1. GlideSystem (and gs.getProperty by extension) is only available server side and this is a client side script. Also, I would put this info inside the addLoadEvent's anonymous function. To fix this in the easiest way possible, try the following edit:
addLoadEvent(function() {
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';
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2014 08:54 AM
Thank you! Now - one last problem (😞 When an ITIL user gets directed back to the ITIL view, their homepage isn't rendering? Any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2014 09:05 AM
I have heard of this one before. Try adding a try/catch block around the function inside the addLoadEvent.
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';
}
}
catch (err) {
}
});