Help with setting a Dashboard as a default homepage

yltsai
Mega Guru

There is a scoped application for certain role users (Senior managers) . The managers would like to see a reporting dashboard as their homepage. There are many users with such role and the development team does not have admin access to the Prod. So, manual update to user preference is out of question.

I searched posts and found a link below

https://community.servicenow.com/community?id=community_question&sys_id=44390fe1db5cdbc01dcaf3231f96...

The team faced challenges.

1. The BR needs to implemented on a global scope table sys_user_has_role and the business side would not permit to add more configurations to the global scope. So, we wanted to implement a fix script.

2. The fix script states to use a page's sys_id but we do use "homepage" but a Dashboard [pa_dashbaord] and we cannot just put the dashboard sys_id. Can we?

3. Due to the deadline and the QA is under way, we cannot rebuild a homepage now.

Please help.

1 ACCEPTED SOLUTION

Try the below script

var iRole = new GlideRecord('sys_user_has_role');
iRole.addQuery('role', 'e1a3c4f8df93210068c37a0d3df26321');
iRole.query();
while(iRole.next()) {
	var page = new GlideRecord('sys_user_preference');
	page.addQuery('name', 'com.snc.pa.ui.preferences_dashboards');
	page.addQuery('user', iRole.user);
	page.query();
	if(page.next()) {
		page.value = '{"last":"a64b7031d7201100b96d45a3ce610335"}';
		page.description = 'Set by a fix script';
		page.update();
	}
	else {
		page.description = 'Set by a fix script';
		page.name = 'com.snc.pa.ui.preferences_dashboards';
		page.type = 'string';
		page.value = '{"last":"a64b7031d7201100b96d45a3ce610335"}';
		page.user = iRole.user;
		page.insert();
	}
	
}

 

And if idea is to run the script only once

use the below script

var iRole = new GlideRecord('sys_user_has_role');
iRole.addQuery('role', 'e1a3c4f8df93210068c37a0d3df26321');
iRole.query();
while(iRole.next()) {
	var page = new GlideRecord('sys_user_preference');
		page.description = 'Set by a fix script';
		page.name = 'com.snc.pa.ui.preferences_dashboards';
		page.type = 'string';
		page.value = '{"last":"a64b7031d7201100b96d45a3ce610335"}';
		page.user = iRole.user;
		page.insert();
	
}

View solution in original post

7 REPLIES 7

Inactive_Us1957
Kilo Guru

You can pass the URL of the dashboard in "glide.home.page" property.

Kanchan,

 

Thank you for your suggestion. But I have questions about the approach.

1. We want to set a dashboard as a homepage to only one group of managers with a role not for all users. The change to glide.home.page property will affect all users. Is that right?

2. The team is restricted to add any more configurations to the global scope but within the given scoped application development. Is it possible to build a scoped application property to set the default homepage for a group with a special role?

 

In fix script

use the below lines to popuate the dashboard user preference

page.name = 'com.snc.pa.ui.preferences_dashboards'
page.value = '{"last":"ecd63570ff2302001e68ffffffffffe0"}';​

 

To get the sys_id of the dasboard use copy link feature on dashboard page

https://xxxxx.service-now.com/$pa_dashboard.do?embedded=true&dashboard=ecd63570ff2302001e68ffffffffffe0&tab=acf67570ff2302001e68ffffffffff30

Hey, DVP,

Thank you for your suggestion.

Where in the fix script should I replace with the 2 lines of code that you suggested?

I have the code below for testing. I highlighted two lines of code.

var iRole = new GlideRecord('sys_user_has_role');
iRole.addQuery('role', 'e1a3c4f8df93210068c37a0d3df26321');
iRole.query();
while(iRole.next()) {
var page = new GlideRecord('sys_user_preference');
page.addQuery('name', 'homepage');
page.addQuery('user', iRole.user.toString());
page.query();
if(page.next()) {
page.value = 'https://dev12355.service-now.com/$pa_dashboard.do?embedded=true&dashboard=a64b7031d7201100b96d45a3ce610335&tab=c15b3831d7201100b96d45a3ce6103c2';
page.description = 'Set by a fix script';
page.update();
}
else {
page.description = 'Set by a fix script';
page.name = 'Testing Homepage';
page.type = 'string';
page.value = 'https://dev12355.service-now.com/$pa_dashboard.do?embedded=true&dashboard=a64b7031d7201100b96d45a3ce610335&tab=c15b3831d7201100b96d45a3ce6103c2';
page.user = iRole.user.toString();
page.insert();
}

}