- 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-24-2021 11:58 AM
I have not ran the script yet, I figured I'd post it here before running it since it's been a bit since I used GlideScript. I looked in Performance Analytics and I couldn't find anything that would also show what assignment groups have had 0 incidents assigned to them in the past 6 months. I can see what AGs have had incidents assigned but it doesn't show me what has had none. I could just remove those ones from the list but then I would be assuming that the rest haven't had any, if I do it with a script I can confirm that the count is 0 before we remove those assignment groups. Essentially we are doing an assignment group cleanup.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2021 09:39 PM
You create a breakdown for the assignment group field. Then add that breakdown to the incident indicator that is counting incidents. You can set it up to count by day or by month.
Then when you look at the indicator you can then pick that breakdown and it will show you every group that is part of your assignment group breakdown and how many incidents were assigned, even if its zero. From there you can look at it by Month, 3 months, quarterly sum and a bunch of others.
The PA can then be used for other things like whats the work load for each group based on the number of incidents that it handles and so on.
Another way you can do this is with a remote table (i.e. scripted table). Since it runs a script to generate the data in the table you can just write the script so it queries the data the way you want to calculate the counts and then anytime someone runs a report on the table the system will build the data in it on demand from the data in the system and you will not have to run a script each time and send someone the results. Remote tables can also have flows run against them along with BR's so there is a bunch of automation you could add if so inclined.
Just tossing out other ways to go about it since I'm sure you will have to do this again and again as time goes on.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2021 11:21 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2021 12:05 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2021 09:54 PM
For this to work the way you want you would have to create a database view with the sys_user_group table first and then select Left join when you add the incident table. Then the view will include all of the groups from the group table no matter what.