Employee Center favorites

Jim_Keefover
Kilo Expert

How do we report on the number of articles and services that are favorited within the Employee Center? Is there a way to find the top 10 favorites.

 

Thank you in advance.

2 ACCEPTED SOLUTIONS

Pooja_Patil
ServiceNow Employee
ServiceNow Employee

@Jim_Keefover ,

Favorited items are stored in sp_favorite.

Following query will give you records grouped by each item, ordered by count descending.

 

var limit = 10;
var favoriteGr = new GlideAggregate("sp_favorite");
favoriteGr.addAggregate("COUNT", "reference_document");
favoriteGr.orderByAggregate("COUNT", "reference_document");
favoriteGr.query();
var i = 0;
while(favoriteGr.next() && (i++ < limit)) {
    gs.info("Item: " + favoriteGr.reference_document + " Count: " + favoriteGr.getAggregate("COUNT", "reference_document"));
}

 

~ Pooja

Please mark this as helpful and accepted solution if applicable.

View solution in original post

Jim_Keefover
Kilo Expert

Hello Pooja!
Thank you for your help! The table sp_favorite helps us with our quick reporting need.  I will work with the code in our stage environment and see how it helps also.

Thanks!  🙂

 

View solution in original post

2 REPLIES 2

Pooja_Patil
ServiceNow Employee
ServiceNow Employee

@Jim_Keefover ,

Favorited items are stored in sp_favorite.

Following query will give you records grouped by each item, ordered by count descending.

 

var limit = 10;
var favoriteGr = new GlideAggregate("sp_favorite");
favoriteGr.addAggregate("COUNT", "reference_document");
favoriteGr.orderByAggregate("COUNT", "reference_document");
favoriteGr.query();
var i = 0;
while(favoriteGr.next() && (i++ < limit)) {
    gs.info("Item: " + favoriteGr.reference_document + " Count: " + favoriteGr.getAggregate("COUNT", "reference_document"));
}

 

~ Pooja

Please mark this as helpful and accepted solution if applicable.

Jim_Keefover
Kilo Expert

Hello Pooja!
Thank you for your help! The table sp_favorite helps us with our quick reporting need.  I will work with the code in our stage environment and see how it helps also.

Thanks!  🙂