The CreatorCon Call for Content is officially open! Get started here.

Set Home Page based on role

ramesh2978
Mega Contributor

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?

2 ACCEPTED SOLUTIONS

AnveshKumar M
Tera Sage
Tera Sage

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.

  1. my_home_navigation_page should have the value as $pa_dashboard.do
  2. com.snc.pa.ui.preferences_dashboards should have the value as {"last":" YOUR Dashboard SYS_ID"}
Thanks,
Anvesh

View solution in original post

@ramesh2978 Please try the below code.

 

AnveshKumarM_0-1697525431764.png

 

(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);
Thanks,
Anvesh

View solution in original post

4 REPLIES 4

AnveshKumar M
Tera Sage
Tera Sage

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.

  1. my_home_navigation_page should have the value as $pa_dashboard.do
  2. com.snc.pa.ui.preferences_dashboards should have the value as {"last":" YOUR Dashboard SYS_ID"}
Thanks,
Anvesh

@AnveshKumar M Can you please help with code?

@ramesh2978 Please try the below code.

 

AnveshKumarM_0-1697525431764.png

 

(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);
Thanks,
Anvesh

@AnveshKumar M Thank you so much for the support. I really appreciate it.