- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2022 06:07 PM
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.
Solved! Go to Solution.
- Labels:
-
Personal Developer Instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2022 11:02 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2022 10:10 PM
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
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2022 09:56 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2022 10:03 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2022 11:02 PM
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