Homepage defaults to "Dashboards"

Ben42
Tera Contributor

Hello Folks,

I am trying to set homepage as defaulted to "Dashboards" when a user from specific group is logged in and also trying to default them the user to particular dashboard. I wrote a after insert or update BR on sys_user_grmemeber table with below script. but doesn't work. 

find_real_file.png

(function executeRule(current, previous /*null when async*/ ) {

var setPADashboard = function(userSysId, dashboardName) {

/* // Fetch dashboard
var grDashboard = new GlideRecord('pa_dashboards');
if (!grDashboard.get('sys_id', '2f452d2f8dbc7851046b45641ca9619c2')) //dashboard sysid
return; */

// Make sure user's home page is set to dashboards
var grPref = new GlideRecord('sys_user_preference');
grPref.addQuery('user', gs.getUserID());
grPref.addQuery('name', 'my_home_navigation_page');
grPref.query();
if (grPref.next()) {
if (grPref.getValue('value') !== '$pa_dashboard.do') {
grPref.setValue('value', '$pa_dashboard.do');
grPref.update();
}
} else {
grPref = new GlideRecord('sys_user_preference');
grPref.initialize();
grPref.setValue('user', gs.getUserID());
grPref.setValue('name', 'my_home_navigation_page');
grPref.setValue('value', '$pa_dashboard.do');
grPref.insert();
}

// Set the user preference to point to that dashboard

grPref = new GlideRecord('sys_user_preference');
grPref.addQuery('user', gs.getUserID());
grPref.addQuery('name', 'com.snc.pa.ui.preferences_dashboards');
grPref.query();
if (grPref.next()) {
var dash_settings = JSON.parse(grPref.getValue('value'));
dash_settings.last = grDashboard.getValue('sys_id');
grPref.setValue('value', JSON.stringify(dash_settings));
grPref.update();
} else {
grPref = new GlideRecord('sys_user_preference');
grPref.initialize();
grPref.setValue('user', gs.getUserID());
grPref.setValue('name', 'com.snc.pa.ui.preferences_dashboards');
grPref.setValue('value', JSON.stringify({
last: grDashboard.getValue('sys_id')

}));
grPref.insert();
}
};

})(current, previous);

 

Thanks,

Ben.

1 REPLY 1

Paul Curwen
Giga Sage

Your approach seems basically orrect.

Are the user preferences not getting set for the user? i.e you are not seeing the user preference entries for :

  • name = my_home_navigation_page value = $pa_dashboard.do
  • name = com.snc.pa.ui.preferences_dashboards value = <JSON string> 

If not, insert some gs.log() statements in your code to see where it is failing. 

***If Correct/Helpful please take time mark as Correct/Helpful. It is much appreciated.***

Regards

Paul