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
‎11-04-2021 04:08 PM
I think you can create a database view joining the alm_hardware and sys_user tables and query that. Each record will have data from both tables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2024 04:23 AM - edited ‎07-11-2024 04:31 AM
You can use .setGroup(false) to return each row (instead of a group) and the rows will be sorted by the grouping
var ga = new GlideAggregate('incident');
ga.groupBy('assigned_to');
ga.setGroup(false);
/*
- Incident1 Abel Tutor
- Incident2 Abel Turor
- Incident3 David Loo
- Incident4 David Loo
...
*/