Display Group Members of Child Groups

MGanon
Tera Guru

We have groups at 2 levels. Understanding that the group member tab shows the list of members of that group, we need to also display the members of children groups.

For example: Group C has members X, Y, & Z and is a child to group P. Group P has members A, B, & C. When a user opens group P, that user needs a related list showing the group C members. Ultimately, we would like a single list showing all member of the group and all children but a second tab showing just the children group members works for now.

Is this possible? If so, how?

Thanks

1 ACCEPTED SOLUTION

Nick Peters
Tera Guru

You can accomplish this by creating a new Relationship record and using it to query for group members of child groups.

Go to System Definition > Relationships and create a new record.

Name:
Child Group Members->Parent Group

Applies to table:
Group [sys_user_group]

Queries from table:
Group Member [sys_user_grmember]

Query with:

(function refineQuery(current, parent) {

	// Add your code here, such as current.addQuery(field, value);
	current.addQuery('group.parent', parent.sys_id);

})(current, parent);

Go to a group record, open the context menu, and go to Configure > Related Lists. Select the relationship record you just made. That's it! You may want to rename the related list on the form to give it a better name.

View solution in original post

13 REPLIES 13

Nick Peters
Tera Guru

You can accomplish this by creating a new Relationship record and using it to query for group members of child groups.

Go to System Definition > Relationships and create a new record.

Name:
Child Group Members->Parent Group

Applies to table:
Group [sys_user_group]

Queries from table:
Group Member [sys_user_grmember]

Query with:

(function refineQuery(current, parent) {

	// Add your code here, such as current.addQuery(field, value);
	current.addQuery('group.parent', parent.sys_id);

})(current, parent);

Go to a group record, open the context menu, and go to Configure > Related Lists. Select the relationship record you just made. That's it! You may want to rename the related list on the form to give it a better name.

I want to add the child members to the parent group directly. I've been trying to wrap my head around a business rule to do this. This is the closest post I've seen to what I am doing - but I don't want a new related list for child members.  The AD groups are nested.  Existing AD groups are placed in the new ServiceNow AD group. I want those users to just all show in the ServiceNow assignment groups - everything being maintained in AD.  Thoughts?

Hi Cheri,
Originally, we wanted to post members of children groups directly to the parent group as members. We decided against it because of removals. Removing a member from the parent group is easy if the user only belongs to 1 child group. It gets more complicated when a user belongs to multiple children groups and leave 1 or all of them. How does ServiceNow know to remove that user from the parent without querying all of them? Instead, we push only the managers of the children groups to become members of the parent group. (I can share that script if you want.)
The secondary benefit of this approach is that AD group managers become queue managers and get the out-of-box ServiceNow notifications.

It is not the answer you wanted but hopefully it helps.

Community Alums
Not applicable

You can create relationship by following the steps provided by nick with details as shown below.

 

find_real_file.png

 

Script : Modify below script as per your requirement

 

(function refineQuery(current, parent) {
var childGroups = [];
var grp = new GlideRecord('sys_user_group');
grp.addActiveQuery();
grp.addQuery('parent', parent.getValue('sys_id'));
grp.query();
while(grp.next()){
childGroups.push(grp.getValue('sys_id'));
}
if(childGroups.length >0){
current.addQuery('group', 'IN', childGroups.toString());
}else{
current.addQuery('group','xyz');//Invalid to query not to return anything if no child
}

})(current, parent);

 

Add Child Group Members related list on group form as below 

find_real_file.png

 

find_real_file.png

CAB Approval is Parent of APplication Development

 

find_real_file.png