- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 10:22 PM
I want to print assignment group : incident numbers......... like Hardware : INC000111,INC0000233
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2023 12:24 PM
@Avinash5410 Here is the script which can get you this data.
var glideIncident = new GlideAggregate('incident');
glideIncident.groupBy('assignment_group');
glideIncident.addAggregate('COUNT');
glideIncident.query();
while(glideIncident.next()){
var assignment_group ={'id':glideIncident.getValue('assignment_group'),'name':glideIncident.getDisplayValue('assignment_group')};
if(assignment_group.id!=''){
var glideIncidentRec = new GlideRecord('incident');
glideIncidentRec.addQuery('assignment_group',assignment_group.id);
glideIncidentRec.query();
var incidentNum ='';
while(glideIncidentRec.next()){
incidentNum = incidentNum+glideIncidentRec.getValue('number')+',';
}
gs.print(assignment_group.name+':'+incidentNum);
}
}
Here is the output.
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2023 12:29 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2023 02:33 PM
// Create a GlideAggregate query on the incident table
var incidentGR = new GlideAggregate('incident');
// Group the records by assignment group
incidentGR.addAggregate('COUNT', 'number');
incidentGR.groupBy('assignment_group');
// Execute the query
incidentGR.query();
// Initialize a variable to store the results
var result = '';
// Loop through the groups and their counts
while (incidentGR.next()) {
var assignmentGroup = incidentGR.getDisplayValue('assignment_group');
var incidentCount = incidentGR.getAggregate('COUNT', 'number');
// Append the assignment group and incident numbers to the result string
result += assignmentGroup + ': ';
// Query the incident numbers for the current assignment group
var incidentNumbers = new GlideRecord('incident');
incidentNumbers.addQuery('assignment_group', incidentGR.assignment_group);
incidentNumbers.query();
// Loop through the incident records and append their numbers to the result
while (incidentNumbers.next()) {
result += incidentNumbers.number + ',';
}
// Remove the trailing comma
result = result.slice(0, -1);
// Add a line break
result += '\n';
}
// Log or display the result
gs.info(result);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2023 06:32 PM
could you pls tell, how to get the output in json fotmat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2023 12:31 AM
But printing only first number, what's wrong in the script