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

Script Include:

getuserMembers: function() {
        var allUsers = '';
        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('group.name', 'CAB Approval'); //Use your AD group name
        gr.query();
        while (gr.next()) {
            allUsers = gr.user.toString() + ',' + allUsers;
        }
        return 'sys_idIN' + allUsers;
    },

Ref Condition:

javascript: new SCriptIncludeName().functionName();

 

Hope it helps

Thanks,

Murthy

Thanks,
Murthy

Saurav11
Kilo Patron
Kilo Patron

Hello

Thomas Can you be a little more specific in uour requirement Specific group of user but is the grp static or is it dynamic based on something or is there any field for grp on the form

 

Thanks

This group is azure AD group, the members are imported from AD into this group. I want to show only these users on the reference variables.

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