I want to print groupby assignmentgroup and with count,numbers as well
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2025 01:21 AM
I want to print groupby assignmentgroup and with count,numbers as well
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2025 04:23 AM
Hello @ganeshnerni,
// Create a GlideAggregate object for the 'incident' table
var ga = new GlideAggregate('incident');
// Group by the 'assignment_group' field
ga.groupBy('assignment_group');
// Add a count aggregate to get the number of incidents per group
ga.addAggregate('COUNT');
// Execute the query
ga.query();
// Loop through the results and print the assignment group and count
while (ga.next()) {
var groupName = ga.getDisplayValue('assignment_group') || 'No Assignment Group'; // Handle null/empty groups
var count = ga.getAggregate('COUNT');
gs.print('Assignment Group: ' + groupName + ' | Count: ' + count);
}
Please accept my solution and mark as helpful if it works
Thanks
Vijay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2025 08:37 AM
Hi @ganeshnerni,
var agg = new GlideAggregate('incident');
agg.addAggregate('COUNT');
agg.groupBy('assignment_group');
agg.query();
while (agg.next()) {
var groupName = agg.assignment_group.getDisplayValue(); // Get group name
var count = agg.getAggregate('COUNT'); // Get count of records
gs.info('Assignment Group: ' + groupName + ', Count: ' + count);
// Fetch numbers for this assignment group
var gr = new GlideRecord('incident');
gr.addQuery('assignment_group', agg.assignment_group);
gr.query();
var numbers = [];
while (gr.next()) {
numbers.push(gr.number.toString());
}
gs.info('Numbers: ' + numbers.join(', '));
}
Thanks and Regards,
Pratap Singh Sisodia