CI Owner needs to be directed to CMDB workspace as default homepage
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2023 09:11 AM - edited 07-20-2023 11:44 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2023 10:23 AM
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);
})();
Regards,
Riya Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2023 11:28 AM
Sorry that did not work. Very similar code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2023 11:53 AM
@Ankur Bawiskar any ideas? You have answered quite a few of my posts years ago and looks like you're still going
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2023 08:33 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader