Reference qualifier for two security groups.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2025 12:20 PM
Hello,
Appreciate your help.
I have a requirement to select users in a certain group into Manager field, when a 'Company" is selected in catalog form.
I have a Ref qualifier in Manager field written. I need "Group A" to be chosen for any and all companies A, B, C and D.
But when certain company say " Company C" is selected, users from 2 groups( Group A and Group B) needs to be displayed in manager feild.
How to pull up two groups here based on company" Company C".
javascript: 'active=true^company=' + current.variables.company + '^sys_idIN' + getIDs("3c292940472cfd10f726ba67436d43b5");
function getIDs(grp) {
var m = GlideUserGroup.getMembers(grp);
var ids = [];
while (m.next()) {
ids.push(m.getValue('user'));
}
return ids.toString();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2025 12:38 PM
Hi,
Create a script include with a function that evaluates the input of the variable, and returns an encoded query to be used by the ref qualifier.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2025 08:36 PM - edited 04-29-2025 09:43 PM
Hi @Shree Nag ,
try this
replace company c sysid and group 2 sysid with actual values
javascript & colon;'active=true^company=' + current.variables.company + '^sys_idIN' + getIDs("3c292940472cfd10f726ba67436d43b5") + ',' + (current.variables.company == 'COMPANY C SYSID' ? getIDs('GROUP 2 sysid') : '');
function getIDs(grp) {
var m = GlideUserGroup.getMembers(grp);
var ids = [];
while (m.next()) {
ids.push(m.getValue('user'));
}
return ids.toString();
}
I agree with @OlaN better wrap this in a script include if just for one company as you have stated you can try the code I have shared if you want to scale it up further better wrap this up into a script include
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2025 09:32 PM
try this in reference qualifier
If you want you can move this to script include function and call it from reference qualifier
javascript: 'active=true^company=' + current.variables.company + '^sys_idIN' + getIDs(current.variables.company);
function getIDs(company) {
var ids = [];
if (company == 'Company C SysId') {
ids = ids.concat(getGroupMembers('Group A SysId'));
ids = ids.concat(getGroupMembers('Group B SysId'));
} else {
ids = getGroupMembers('Group A SysId');
}
return ids.toString();
}
function getGroupMembers(group) {
var m = GlideUserGroup.getMembers(group);
var ids = [];
while (m.next()) {
ids.push(m.getValue('user'));
}
return ids;
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2025 10:21 PM
@Shree Nag Please try with below updated code:
(function() {
var company = current.variables.company;
var userIds = [];
// Group sys_ids
var groupA = '3c292940472cfd10f726ba67436d43b5'; // Group A
var groupB = 'replace with group B sysid'; // Group B sysid
// For Companies A, B, C, D -> Default to Group A
if (company == 'company_sys_id_A' || company == 'company_sys_id_B' || company == 'company_sys_id_C' || company == 'company_sys_id_D') {
userIds = getMembers(groupA);
// Special case for Company C
if (company == 'company_sys_id_C') {
userIds = userIds.concat(getMembers(groupB));
}
}
return 'active=true^sys_idIN' + userIds.join(',');
function getMembers(groupSysId) {
var ids = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', groupSysId);
gr.query();
while (gr.next()) {
ids.push(gr.user.toString());
}
return ids;
}
})();
Please mark correct/helpful if this helps you!