How to show group member by selecting choice variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
Hi All,
I have below requirement kidly let me know how to resolve it
I have one catalog item in witch there are 2 variables available
1 has 2 choices called A & B and another one is reference
If A is selected then menber of software group will be shown in reference field means in another variable and if B choice will be selected then all users from user table will be shown.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
add this in advanced ref qualifier
Note: Ensure you give correct choice variable name, give correct choice value to compare
I assume your reference variable refers to sys_user_grmember
javascript: var choiceValue = current.variables.choiceVariableName;
var query = '';
if(choiceValue == 'A'){
query = 'group.nameINSoftware'; // give the group name here
}
query;
If your reference variable refers to sys_user then use this
javascript: var choiceValue = current.variables.choiceVariableName;
var query = '';
if (choiceValue == 'A') {
var groupSysId = 'your_group_sys_id_here'; // Replace with actual sys_id
var members = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', groupSysId);
gr.query();
while (gr.next()) {
members.push(gr.getValue('user'));
}
query = 'sys_idIN' + members.toString();
}
query;
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
Hi @jui,
You can use Advanced Reference Qualifier on Reference field to achieve this requirement.
You also need to create a script include to get the group members of "Software" group.
Advanced Reference Qualifier:
javascript:
var query;
var groupName = <group_sys_id>;
var membershipUtils = new global.GroupMemberUtils();
if (current.variables.choice_variable == "A") {
query = 'active=true^sys_idIN' + membershipUtils.getMembersByGroupId(groupName);
} else {
query = 'active=true';
}
query;
Sample Script Include:
var GroupMemberUtils = Class.create();
GroupMemberUtils.prototype = {
initialize: function () {},
getMembersByGroupId: function (groupSysId) {
var members = [];
if (!groupSysId) {
return members;
}
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', groupSysId);
gr.query();
while (gr.next()) {
members.push(gr.user.toString());
}
return members;
},
type: 'GroupMemberUtils'
};
Thanks
Anand