- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â05-06-2024 06:42 AM
Hello Experts,
I want to print the incident category with the incident number I have written below script
but is not working. please guide me on this.
thank you.
var incidentGR = new GlideAggregate('incident');
incidentGR.addQuery('active', true);
incidentGR.groupBy('category');
incidentGR.addAggregate('COUNT', 'number');
incidentGR.query();
while (incidentGR.next()) {
var category = incidentGR.category.getDisplayValue();
var incidentCount = incidentGR.getAggregate('COUNT', 'number');
var number=incidentGR.number;
gs.info('Category: ' + category + ' - Incident Count: ' + incidentCount);
gs.print('number'+number);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â05-06-2024 09:41 AM
@Mark Wood Try this
var incidentGR = new GlideAggregate('incident');
incidentGR.addQuery('active', true);
incidentGR.groupBy('category');
incidentGR.addAggregate('COUNT', 'number');
incidentGR.query();
while (incidentGR.next()) {
var category = incidentGR.getValue('category'); // Get the category value directly
var incidentCount = incidentGR.getAggregate('COUNT', 'number');
// Query the incident records for numbers within this category
var incidentNumbers = new GlideRecord('incident');
incidentNumbers.addQuery('category', category);
incidentNumbers.query();
// Print each incident number along with the category and count
while (incidentNumbers.next()) {
gs.info('Category: ' + category + ' - Incident Count: ' + incidentCount);
gs.print('Incident Number: ' + incidentNumbers.number);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â05-06-2024 07:01 AM
Hi @Mark Wood ,
Please try below code:-
var incidentGR = new GlideAggregate('incident');
incidentGR.addQuery('active', true);
incidentGR.groupBy('category');
incidentGR.addAggregate('COUNT');
incidentGR.query();
while (incidentGR.next()) {
var category = incidentGR.category.getDisplayValue();
var incidentCount = incidentGR.getAggregate('COUNT');
var number=incidentGR.number;
gs.info('Category: ' + category + ' - Incident Count: ' + incidentCount);
}
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Ranjit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â05-06-2024 09:41 AM
@Mark Wood Try this
var incidentGR = new GlideAggregate('incident');
incidentGR.addQuery('active', true);
incidentGR.groupBy('category');
incidentGR.addAggregate('COUNT', 'number');
incidentGR.query();
while (incidentGR.next()) {
var category = incidentGR.getValue('category'); // Get the category value directly
var incidentCount = incidentGR.getAggregate('COUNT', 'number');
// Query the incident records for numbers within this category
var incidentNumbers = new GlideRecord('incident');
incidentNumbers.addQuery('category', category);
incidentNumbers.query();
// Print each incident number along with the category and count
while (incidentNumbers.next()) {
gs.info('Category: ' + category + ' - Incident Count: ' + incidentCount);
gs.print('Incident Number: ' + incidentNumbers.number);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â05-06-2024 11:36 AM
@Mark Wood Here is the script you should try.
var incidentGR = new GlideAggregate('incident');
incidentGR.addQuery('active', true);
incidentGR.groupBy('category');
incidentGR.addAggregate('COUNT');
incidentGR.query();
while (incidentGR.next()) {
var incidentCount = incidentGR.getAggregate('COUNT');
gs.info('Category: ' + incidentGR.category.getDisplayValue() + ' - Incident Count: ' + incidentCount);
}