Blog

Find Incidents or Requests Group Members Submitted

There are system functions in ServiceNow used to find items assigned to you or your group to work on.  Examples include getMyAssignments(), getMyGroups(), and getMyApprovals().  They are used throughout ServiceNow for filters and reports.  

What if you wanted to find all the requests or incidents that members of all your groups submitted?  I have a way to do that with a new Script Include called getMyGroupMembers.

Step 1: Find ArrayUtil Script Include and set to Client Callable

Script Include: ArrayUtil
Client Callable: true

Step 2: Add getMyGroupMembers Script Include

Script Include: getMyGroupMembers
Client Callable: true
Description: Returns all members of your group
function getMyGroupMembers(){
//Set Variables
var myUserObject = gs.getUser();
var myUserGroups = myUserObject.getMyGroups();
var groupsArray = [];
var groupMembers = [];
var arrayUtil = new ArrayUtil();
var it = myUserGroups.iterator();
//gs.log('Get all my Groups into an array');
for (var i = 0; it.hasNext(); i++) {
var myGroup = it.next();
groupsArray[i]=myGroup;
}
//gs.log('Get all my Group Members into an array;);
for (var i2 = 0; i2 < groupsArray.length; i2++) {
var grGroupMembers = new GlideRecord('sys_user_grmember');
grGroupMembers.addQuery('group',groupsArray[i2]);
grGroupMembers.query();
while (grGroupMembers.next()) {
groupMembers.push(grGroupMembers.user.sys_id.toString());
}
}
//gs.log('Return Unique Group Member Array');
return arrayUtil.unique(groupMembers);
}

Step 3: Example Report: My Group's Requested Requests

Name:My Group's Requested Requests
Type: List
Table: Request [sc_request]
Columns: Number, Requested For, Opened By, Request State, Due Date
Filter: Requested For is javascript:getMyGroupMembers()

Step 4: Example Report: My Group's Caller Incidents

Name:My Group's Caller Incidents
Type: List
Table: Incident [Incident]
Columns: Number, Caller, Short Description, Priority, State
Filter: Requested For is javascript:getMyGroupMembers()

You can also make other reports using this, like My Group's Opened Tasks.  Note that depending on the size of your ServiceNow instance, this might not be feasible.  If you have a system with members part of 100 groups with 200 members per group, this might not work well.  However, for many small to mid-range ServiceNow instances, you can run these reports fine.

Hope that helps,
Mike