The Zurich release has arrived! Interested in new features and functionalities? Click here for more

UI Navigation Redirection

sry
Giga Guru

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;

    }
})();

 

1 ACCEPTED SOLUTION

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();
})();

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@sry 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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();
})();

@sry 

where have you written the above script?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

My apologies Ankur. I created a record for table "INCIDENT" in "SYS_NAVIGATOR" table.

 

Thanks,

Sry