- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2023 11:29 PM
I was trying to make a Dashboard as user Home Page in ServiceNow based on role assigned. Can some one please point me in the right direction to do this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 07:50 AM
Hi @ramesh2978
Write an After - Insert BR on sys_user_has_role table and check for the role for which you are trying to set the dashboard as home page. Then in the script check for the following two preferences in sys_user_preference table.
- my_home_navigation_page should have the value as $pa_dashboard.do
- com.snc.pa.ui.preferences_dashboards should have the value as {"last":" YOUR Dashboard SYS_ID"}
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 11:51 PM
@ramesh2978 Please try the below code.
(function executeRule(current, previous /*null when async*/ ) {
var dbGr = new GlideRecord('sys_user_preference');
dbGr.addQuery('name', 'my_home_navigation_page');
dbGr.addQuery('user', current.user.sys_id + '');
dbGr.query();
if (dbGr.next()) {
dbGr.value = '$pa_dashboard.do';
dbGr.description = 'Automatically set based on Role';
dbGr.update();
} else {
dbGr.initialize();
dbGr.description = 'Automatically set based on Role';
dbGr.name = 'com.snc.pa.ui.preferences_dashboards';
dbGr.type = 'string';
dbGr.value = '$pa_dashboard.do';
dbGr.user = current.user.sys_id + '';
dbGr.insert();
}
var page = new GlideRecord('sys_user_preference');
page.addQuery('name', 'com.snc.pa.ui.preferences_dashboards');
page.addQuery('user', current.user.sys_id + '');
page.query();
if (page.next()) {
page.value = '{"last":"YOUR_DASHBOARD_SYS_ID"}';
page.description = 'Automatically set based on Role';
page.update();
} else {
page.initialize();
page.description = 'Automatically set based on Role';
page.name = 'com.snc.pa.ui.preferences_dashboards';
page.type = 'string';
page.value = '{"last":"YOUR_DASHBOARD_SYS_ID"}';
page.user = current.user.sys_id + '';
page.insert();
}
})(current, previous);
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 07:50 AM
Hi @ramesh2978
Write an After - Insert BR on sys_user_has_role table and check for the role for which you are trying to set the dashboard as home page. Then in the script check for the following two preferences in sys_user_preference table.
- my_home_navigation_page should have the value as $pa_dashboard.do
- com.snc.pa.ui.preferences_dashboards should have the value as {"last":" YOUR Dashboard SYS_ID"}
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 09:03 AM
@AnveshKumar M Can you please help with code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 11:51 PM
@ramesh2978 Please try the below code.
(function executeRule(current, previous /*null when async*/ ) {
var dbGr = new GlideRecord('sys_user_preference');
dbGr.addQuery('name', 'my_home_navigation_page');
dbGr.addQuery('user', current.user.sys_id + '');
dbGr.query();
if (dbGr.next()) {
dbGr.value = '$pa_dashboard.do';
dbGr.description = 'Automatically set based on Role';
dbGr.update();
} else {
dbGr.initialize();
dbGr.description = 'Automatically set based on Role';
dbGr.name = 'com.snc.pa.ui.preferences_dashboards';
dbGr.type = 'string';
dbGr.value = '$pa_dashboard.do';
dbGr.user = current.user.sys_id + '';
dbGr.insert();
}
var page = new GlideRecord('sys_user_preference');
page.addQuery('name', 'com.snc.pa.ui.preferences_dashboards');
page.addQuery('user', current.user.sys_id + '');
page.query();
if (page.next()) {
page.value = '{"last":"YOUR_DASHBOARD_SYS_ID"}';
page.description = 'Automatically set based on Role';
page.update();
} else {
page.initialize();
page.description = 'Automatically set based on Role';
page.name = 'com.snc.pa.ui.preferences_dashboards';
page.type = 'string';
page.value = '{"last":"YOUR_DASHBOARD_SYS_ID"}';
page.user = current.user.sys_id + '';
page.insert();
}
})(current, previous);
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 03:43 AM
@AnveshKumar M Thank you so much for the support. I really appreciate it.