- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2024 02:37 AM
I want to print the incident numbers per assignment group in JSON format.
Eg: {"Group1" : [INC1,INC2,INC3],
"Group2" : [INC4,INC5,INC6]
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2024 03:08 AM - edited 02-02-2024 03:22 AM
Hello @Peter Wood
Try below script
var inc = new GlideRecord('incident');
inc.addEncodedQuery('active=true^short_description=Test');
inc.query();
var incidents = [];
while(inc.next()){
incidents.push({'incident_number': inc.getValue('number'),'assignment_group': inc.getValue('assignment_group')});
}
var groupedIncidents = {};
incidents.forEach(function (incident) {
var group = incident.assignment_group;
var number = incident.incident_number;
if (groupedIncidents[group]) {
groupedIncidents[group].push(number);
} else {
groupedIncidents[group] = [number];
}
});
var jsonResult = JSON.stringify(groupedIncidents);
gs.log(jsonResult);
Regards
Ayan Murshad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2024 03:08 AM - edited 02-02-2024 03:22 AM
Hello @Peter Wood
Try below script
var inc = new GlideRecord('incident');
inc.addEncodedQuery('active=true^short_description=Test');
inc.query();
var incidents = [];
while(inc.next()){
incidents.push({'incident_number': inc.getValue('number'),'assignment_group': inc.getValue('assignment_group')});
}
var groupedIncidents = {};
incidents.forEach(function (incident) {
var group = incident.assignment_group;
var number = incident.incident_number;
if (groupedIncidents[group]) {
groupedIncidents[group].push(number);
} else {
groupedIncidents[group] = [number];
}
});
var jsonResult = JSON.stringify(groupedIncidents);
gs.log(jsonResult);
Regards
Ayan Murshad