CI Owner needs to be directed to CMDB workspace as default homepage

DP10
Tera Contributor

Hello ServiceNow champions, I am trying to do exactly what the title says. I attempted to create a UI script for this to no avail. Does anyone have any ideas on this requirement or can they check this code? Should I not use a UI Script and maybe adjust a system property?

 

 

 

 

// Get the current user
var currentUser = gs.getUser();
var userId = currentUser.getID();

// Query the 'cmdb_ci' table to check if the current user is a CI owner
var ciGr = new GlideRecord('cmdb_ci');
ciGr.addQuery('owned_by', userId);
ciGr.query();

// Set the target URL for redirection
var targetURL = '';
if (ciGr.next()) {
  targetURL = '/now/cmdb/home'; // The URL of the CMDB Workspace
} else {
  targetURL = '/nav_to.do'; // The URL of the default homepage or any other page you want to redirect non-CI owners to
}

// Redirect the user
gs.addInfoMessage('Redirecting to the CMDB Workspace...');
action.setRedirectURL(targetURL);

 

 

 

 

4 REPLIES 4

Riya Verma
Kilo Sage
Kilo Sage

HI There,
Please find the updated code 

(function() {
  // Get the current user
  var currentUser = gs.getUser();
  var userId = currentUser.getID();

  // Query the 'cmdb_ci' table to check if the current user is a CI owner
  var ciGr = new GlideRecord('cmdb_ci');
  ciGr.addQuery('owned_by', userId);
  ciGr.query();

  // Set the target URL for redirection
  var targetURL = '';
  if (ciGr.next()) {
    targetURL = '/now/cmdb/home'; // The URL of the CMDB Workspace
  } else {
    targetURL = '/nav_to.do'; // The URL of the default homepage or any other page you want to redirect non-CI owners to
  }

  // Redirect the user
  gs.addInfoMessage('Redirecting to the CMDB Workspace...');
  action.setRedirectURL(targetURL);
})();
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

DP10
Tera Contributor

Sorry that did not work. Very similar code

DP10
Tera Contributor

@Ankur Bawiskar any ideas? You have answered quite a few of my posts years ago and looks like you're still going

Ankur Bawiskar
Tera Patron
Tera Patron

@DP10 

if you are planning to use UI script then few points

1) it is client side so you need to use g_user.userID to get logged in user sysId

2) action object won't work there

check this link and enhance script

Redirecting user logins - UI Scripts, Login Rules, or Installation Exits 

Also you can check this link on how to redirect users when they login to instance

How to configure redirection for Service Portal 

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