Requirement: query users from a group to a reference field (sys_user).

Thomas98
Tera Expert

Requirement:

Reference field should populate members of a group.

I have a reference field which is referenced to sys_user table. Right now I have all users being populated, but I want users which are a part of a group only to be included in this. 

I know it requires a script include and javacript on the reference qualifier. Could someone help me with the script include and how to call is on the advanced  reference qualifier. 

 

1 ACCEPTED SOLUTION

Sumit Maniktal1
Tera Expert

You can follow this in case your requirement is to just show list if all users who are part of any of the groups in system. You can enhance he script further for more filters in case you want like filter on only users that are active or groups that are active or both

1. Create a script include with name "getUsersWhoAreMemberOfAnyGroup"

2. Set Client callable flag to true

3. Copy/Paste below code in the script include (remove all code that is there already) 

function getUsersWhoAreMemberOfAnyGroup(){
var userArray = [];
var groupMembers = new GlideRecord('sys_user_grmember');
groupMembers.query();
while (groupMembers.next()){
userArray.push(groupMembers.user.sys_id.toString());
}
return userArray;
}

Note: If you change name of script include then change the name of function also to be the same as script include name

4. Now go to dictionary record of your user field where you want to put this filter & click on Advanced View related link

5. In Reference specification section set "Use reference qualifier" field to Advanced

6. In Reference qual field paste below

javascript:"sys_idIN"+getUsersWhoAreMemberOfAnyGroup()

 

Hope this works for you

View solution in original post

8 REPLIES 8

Murthy Ch
Giga Sage

Hi Thomas,

Do you want to show only the users who are part at least in one group?

 

Thanks

Murthy

Thanks,
Murthy

Yes, I want to show only users who are part of a group. I cannot use group member  table as it would not meet the requirement. 

Okie 

You can use reference qualifier and script include.

Have you tried anything or let me know I will help you with the sample code.

 

Thanks,
Murthy

Thanks,
Murthy

@Thomas

Do you want to show only AD group users?

 

Thanks,
Murthy