To Identify Groups with no Activity in ServiceNow

Raagavi K
Tera Contributor

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.

1 ACCEPTED SOLUTION

Brent Sutton
Mega Sage

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.

View solution in original post

7 REPLIES 7

Hi Raagavi, Just checking if my answer solved your question. If so, please mark as correct so this thread can be closed and other community members can benefit from this information. Thanks in advance, Brent P.S. If my suggestion helped then please mark as helpful and/or correct so other community members can benefit from this information.

Surya Malepati2
Tera Contributor

Hi Brent,

 

The script is working.

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, @Raagavi K never got around to mark this post as correct. Hopefully this will prompt him to come back and update the post.