- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2019 08:33 PM
Hi,
Am new to scripting and i want to print the count of incidents per assignment group.
Any scripts available?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2019 09:13 PM
Hi Manikandan,
you can use reporting for this as well.
sample code below:
var gr = new GlideRecord('incident');
gr.addQuery('assignment_group!=NULL');
gr.query();
while(gr.next()){
var gr1 = new GlideRecord('incident');
gr1.addQuery('assignment_group', gr.assignment_group);
gr1.query();
var rowCount = gr1.getRowCount();
gs.print("Incidents for Group: " + gr.assignment_group.getDisplayValue() + " are " + rowCount);
}
the above code can be optimized using GlideAggregate
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2019 09:13 PM
Hi Manikandan,
you can use reporting for this as well.
sample code below:
var gr = new GlideRecord('incident');
gr.addQuery('assignment_group!=NULL');
gr.query();
while(gr.next()){
var gr1 = new GlideRecord('incident');
gr1.addQuery('assignment_group', gr.assignment_group);
gr1.query();
var rowCount = gr1.getRowCount();
gs.print("Incidents for Group: " + gr.assignment_group.getDisplayValue() + " are " + rowCount);
}
the above code can be optimized using GlideAggregate
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2019 08:13 PM
Thank you for the code Ankur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2020 05:44 AM
Hi Manikandan,
Try this piece of code below-
var gr = new GlideAggregate('incident');
gr.groupBy('assignment_group');
gr.query();
while(gr.next()){
gs.print(gr.assignment_group.name);
var gr1 = new GlideRecord('incident');
gr1.addQuery('assignment_group',gr.assignment_group);
gr1.query();
if(gr1.next()){
gs.print(gr1.getRowCount());
}
}