- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2019 11:37 AM
Hi,
We have a recent requirement. From our ServiceNow prod instance, we have to get a list of groups which are active but with no activity. These groups will be planned to removed.
For Example: In incidents which are opened from January 1, 2018 till date, we need the assignment group names which aren't assigned to any of these incidents (if possible, also group names which aren't part of SLA assignment groups history from 2018 start till date).
Please suggest the best way for same.
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2019 12:23 PM
Hi,
You can run this script in a fix script or background script and it will print out the sys_id and name of inactive groups (groups that haven't been assigned to incidents) since the first of January 2018:
//begin with a GlideRecord query to return all active groups
var gr = new GlideRecord("sys_user_group");
gr.addActiveQuery();
gr.query();
var inactiveGroups = []; //set up array to hold inactive group results
//loop through all active groups
while (gr.next()) {
var inactiveGroup = {}; //setup object to hold sys_id and display value of each inactive group
var groupSysId = gr.getUniqueValue(); //sys_id of current group
var groupName = gr.getDisplayValue(); //display value of current group
//new GlideRecord to test if the group has been assigned to any incident from the 1st of Jan 2018 to today
var inc = new GlideRecord("incident");
inc.addEncodedQuery("sys_created_onBETWEENjavascript:gs.dateGenerate('2018-01-01','00:00:00')@javascript:gs.endOfToday()^assignment_group=" + groupSysId);
inc.query();
//if no results are returned we record the inactive group details
if (!inc.next()) {
inactiveGroup = {
value: groupSysId,
display_value: groupName
};
inactiveGroups.push(inactiveGroup); //push details to array
}
}
gs.print("Inactive Groups: " + JSON.stringify(inactiveGroups)); //print out the results
Let me know if this worked for you.
Brent
P.S. If my suggestion helped then please mark as helpful and/or correct so other community members can benefit from this information.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2019 08:20 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2022 12:11 AM
Hi Brent,
The script is working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2022 12:26 PM
Thanks for the feedback Surya. Glad it is working for you 🙂 Please feel free to mark the original post as "Helpful" so it remains the top ranked answer.
Unfortunately,