- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2021 11:34 AM
Hi everyone,
I'm trying to query the incident table and then count how many incidents have been assigned to each assignment group. I would add a column to the sys_user_group table named u_group_incidents and populate that column via a scheduled job. We are trying to detemine how many groups have had 0 incidents assigned to them in the past 6 months. So if I can populate that column and then filter for opened on at or after 6 months, then I should be able to export that to an excel document. However, it's been a while since I used GlideScript and so I wanted to post what I have here first. This is what I have so far, any feedback is appreciated -
var grp = new GlideRecord('sys_user_group');
grp.query();
while(grp.next()){
//Query for the number of incidents per AG
var grpInc = new GlideAggregate('incident');
grpInc.addQuery('assignment_group', grp.sys_id);
grpInc.addAggregate('COUNT');
grpInc.query();
var groupIncidents = 0;
if(grpInc.next()){
groupIncident = grpInc.getAggregate('COUNT');
grp.u_group_incident = groupIncident;
}
//Update the group record with the new counts
grp.update();
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2021 11:52 AM
So did the actual group record have its name field updated or does it just look that way on the incident form? If its the later check to see what field is set to be the display field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2021 10:21 AM
So the script did work, but now something strange is happening, instead of all of the assignment groups showing the names they all show numbers
I'm not even calling that column or writing to it, this is very strange, here is the script -
Here is the dictionary info for that field -

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2021 11:52 AM
So did the actual group record have its name field updated or does it just look that way on the incident form? If its the later check to see what field is set to be the display field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2021 12:03 PM
Thank you Drew! That's what it was!