is there a way to check whether the user is using homepage or dashboard

msm4
Mega Guru

Hello Team,

I m trying to check the whether the using homepage or dashboard by default.. I created a report of user preference table and trying to give some conditions based on name"my_home_navigation_page" and value is not'' $pa_dashboard.do"  but im not getting the accurate report. 

can anyone help me with the condition here.

Many thanks.

6 REPLIES 6

Apurva Malewad1
Kilo Guru

Hi msm,

Basically user preferences value set depending upon where user navigates and it stores that data for particular user.By default homepage opens for any user in ServiceNow whereas PA dashboard opens only when user clicks on the dashboard to open in dashboards view(which is not by default).You can't create report on this table as this is a system table and 'Reporting functionality is available by default for all tables, except for system tables'. I will suggest you to try any other way or check the use case/requirement again as this is not right way.If any concerns, please let me know.

Regards,

Apurva

seanphelan
Tera Expert

Yes there is.  I would save this as a fix script so as the users migrate you can can continue to check and follow up

//user using homepages
var recs = [];

var user = new GlideRecord('sys_user_preference');
user.addQuery('value', 'default');
user.addQuery('name', 'my_home_navigation_page');
user.query();
while (user.next()) {
    var rec = {};

    rec.username = user.user.getDisplayValue();
	rec.username_sysid = user.user.toString();
    rec.hompage_sysid = '';
    rec.homepage_title = '';

    //what is their homepage
    var landingpage = new GlideRecord('sys_user_preference');
    landingpage.addQuery('user', user.user.toString());
    landingpage.addQuery('name', 'homepage');
    landingpage.query();
    if (landingpage.next()) {
        //save this homepage sys id
        rec.hompage_sysid = landingpage.value.toString();

        //get homepage name
        var homepage = new GlideRecord('sys_portal_page');
        if (homepage.get(landingpage.value.toString())) {
            //store the homepage name (title)
            rec.homepage_title = homepage.title.toString();
        }

    }
    //store this user homepage info
    recs.push(rec);
}
//output info
gs.print("Users using homepage: " + recs.length);

for (var i = 0; i < recs.length; i++){
  var obj = recs[i];
  for (var key in obj){
    var value = obj[key];
    gs.print(key + ": " + value);
  }
	gs.print("----------------------------------------------");
}

//com.snc.pa.ui.preferences_dashboards stores thier landingpage "dashboard"
//system user preference set for my_home_navigation_page to dashboards and com.snc.pa.ui.preferences_dashboards for "your default dashboard"
//we can clear com.snc.pa.ui.preferences_dashboards and homepage so they get the default settings if you want to force it on theme

Thank you. This helped me.  Was wondering how I would add to the script to show active users only.  Thank you for your help.

Kyle4
Tera Contributor

In lines 4-8, rather than:

var user = new GlideRecord('sys_user_preference');
user.addQuery('value', 'default');
user.addQuery('name', 'my_home_navigation_page');
user.query();

Try:
var user = new GlideRecord('sys_user_preference');
user.addQuery('value', 'default');
user.addQuery('name', 'my_home_navigation_page');
user.addEncodedQuery('user.active=true');
user.query();