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

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();
	
}

Hey

Any update on this?

If one of the responses provided above answered your question, please mark the response as correct so that others in the future can find it quickly and that it gets removed from the unanswered list.

DVP,

 

I know I am uber late to this party, but you deserve some props.  This is exactly what I was looking for!

 

TY,

Ken