Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

@sry 

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.

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

@sry 

instead of navigation handler, did you check the link I shared?

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