Incident count per assignment group

Tylerjknapp
Tera Contributor

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();
}

 

1 ACCEPTED SOLUTION

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.

View solution in original post

12 REPLIES 12

Tylerjknapp
Tera Contributor

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 find_real_file.png

I'm not even calling that column or writing to it, this is very strange, here is the script - 

 

find_real_file.png

 

Here is the dictionary info for that field -

 find_real_file.png

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.

Tylerjknapp
Tera Contributor

Thank you Drew! That's what it was!