- 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
check this for non-admin
Redirect non-admin users to Service Operations Workspace
also check this link
Role based redirection with SPEntryPage
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
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
where have you written the above script?
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
My apologies Ankur. I created a record for table "INCIDENT" in "SYS_NAVIGATOR" table.
Thanks,
Sry