- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 06:54 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 04:01 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2023 04:03 PM
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! 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 04:01 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2023 04:03 PM
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! 🙂