GlideAggregate GroupBy() - Get records for each group by value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2020 10:14 AM
Hi All,
When we use GlideAggregate to group by, i know it possible to get a count against a grouped by field.
But rather than getting a count, can i get a return of those values. For example on asset table, group by assigned to user (to get distinct user), and return all the asset name for each distinct assigned to user.
var assigned_users = [];
var asset = new GlideAggregate('alm_hardware');
asset.addQuery("sys_updated")<=javascript:gs.daysAgoStart(1)");
asset.addQuery("class", "Computer");
asset.groupBy("assigned_to");
asset.query();
while (asset.next()) {
assigned_users.push(asset.assigned_to.getRefRecord()); //this gets the assigned to user reference in an array
**********<how to get all asset records(name or assettag) for each assigned to user>*********
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2020 10:25 AM
Hi
this article might help you on achieve it:
https://hi.service-now.com/kb_view.do?sysparm_article=KB0745198
If I have answered your question, please mark my response as correct and helpful so that this thread can be closed and others can be benefited by this.
Thank you very much
Cheers
Alberto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-08-2020 07:28 AM
Thanks for sharing, but the approach only gets me the grouping attribute value. What i'm trying to ahchieve is, get records for each distinct instance of a grouping attribute.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2023 02:16 PM
Hi Abbey2, Are you able to find the solution? I am having the similar requirement. Any ideas would be helpful. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2023 02:20 PM
Hi Abbey2, Are you able to find the solution? I am having the similar requirement. Any ideas to achieve this would be appreciated. Thanks!