- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Hi All, hope everyone doing great.
I have been asked to redirect the "admin" users to native UI, and non-admins to "sow" workspace. i have written the below code for incident in "sys_navigator" table. but the redirections is not happening. "Admins" are seeing a blank page saying "too many redirections" .please help me if anyone has solution how to fix it.
code:
(function() {
// Get the clicked incident sys_id
var sysId = g_request.getParameter('sys_id');
if (!sysId) {
return '/incident_list.do'; // fallback if sys_id missing
}
// Check if the logged-in user is an admin
var isAdmin = false;
var gr = new GlideRecord('sys_user_has_role');
gr.addQuery('user', gs.getUserID());
gr.addQuery('role.name', 'admin');
gr.setLimit(1);
gr.query();
if (gr.hasNext()) {
isAdmin = true;
}
if (isAdmin) {
// Admins → open native incident form
return '/incident.do?sys_id=' + sysId;
} else {
// Non-admins → open in SOW (same tab)
return '/now/sow/record/incident/' + sysId;
}
})();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Hi the below script is working. but there is an issue. for non-admins it is going to SOW but in the same window. we want system to open SOW in new window.
(function () {
// Get sys_id only when a record is being opened
var sysId = g_request.getParameter('sys_id');
if (gs.nil(sysId)) {
// Not opening a single record (e.g., list) → keep default
return g_uri.toString();
}
// Only affect non-admins — send them to SOW
if (!gs.getUser().hasRole('admin')) {
// Direct workspace record URL (no nav_to)
return '/now/sow/record/incident/' + sysId;
// If your build requires nav_to wrapper, use this instead:
// return 'nav_to.do?uri=/now/sow/record/incident/' + sysId;
}
// Admins: leave native UI as-is
return g_uri.toString();
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
since that script is server side, I believe you can't have a logic to open in new window
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
instead of navigation handler, did you check the link I shared?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader