- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2024 06:46 AM
Hello community! First time crying for help!
I am working on a service catalog item.
I am trying to use a script include and catalog client script (posted below, adapted from one I found here) and it's not working.
My use case is, the end user selects a user from a reference select box, that pre-populates the owner_asg select box only with groups that user is a member of.
The end user can change the user and the owner_asg box should change available groups to the new users groups.
I'm open to other solutions but thought the script include was the way to go. Any help is appreciated.
Catalog Client Script:
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2024 02:03 PM
@Jason Thornton Here is the solution we finally concluded.
var GroupsMembership = Class.create();
GroupsMembership.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getGroups: function(record) {
gs.info('in script')
var groups = [];
var user = this.getParameter('sysparm_userID');
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', record);
gr.addQuery('group.name','STARTSWITH','ASG');
gr.query();
while (gr.next()) {
groups.push(gr.group.sys_id);
gs.info(gr.group.sys_id)
}
gs.info("record is" + record);
return 'sys_idIN'+groups.toString();
},
type: 'GroupsMembership'
});
GroupsMembership.get = function() {
return new GroupsMembership();
};
Here is the reference qualifier.
//Variable Reference Qualifer Script
javascript: x_scopapp_utils.GroupsMembership.get().getGroups(current.variables.user);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2024 07:42 AM
No joy. Does it matter what my variable name is for the user selection?
Also, do I need to declare the variable on the header of the catalog client script? Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2024 10:08 AM
This was resolved offline. Thanks to Sandeep for the assist.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2024 02:03 PM
@Jason Thornton Here is the solution we finally concluded.
var GroupsMembership = Class.create();
GroupsMembership.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getGroups: function(record) {
gs.info('in script')
var groups = [];
var user = this.getParameter('sysparm_userID');
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', record);
gr.addQuery('group.name','STARTSWITH','ASG');
gr.query();
while (gr.next()) {
groups.push(gr.group.sys_id);
gs.info(gr.group.sys_id)
}
gs.info("record is" + record);
return 'sys_idIN'+groups.toString();
},
type: 'GroupsMembership'
});
GroupsMembership.get = function() {
return new GroupsMembership();
};
Here is the reference qualifier.
//Variable Reference Qualifer Script
javascript: x_scopapp_utils.GroupsMembership.get().getGroups(current.variables.user);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2024 10:34 PM
FYI, that can be solved without a Script Include, which is typically an easier/cleaner solution. Too many jump to Script Includes as a solution to advanced reference qualifiers.
Setup your group variable as a Lookup Select Box with an attribute of "ref_qual_elements=crep_owner". This tells SN to send back the value of that variable to the server for use in the Reference Qualifier (although in Vancouver it does not seem to be required anymore).
Then you set the Reference qualifier field to be:
javascript: var user = gs.getUser().getUserByID(current.variables.crep_owner);
var groups = user.getMyGroups().toArray().join(",");
var reference = "active=true^sys_idIN" + groups;
reference;
And so you end up with this:
And the list of Groups is updated based on the selected User:
The Reference qualifier can also be "simplified" with chaining down to:
javascript:"active=true^sys_idIN" + gs.getUser().getUserByID(current.variables.crep_owner).getMyGroups().toArray().join(",");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2024 04:41 AM - edited 01-27-2024 04:45 AM
This will not work here like that as getUserByID is not supported in scopes.
But if this is for internal use only (not meant to be published in Store), I would still build the solution around getUserByID even if it means I would need to wrap it in a global Script Include, because:
- it honors group hierarchy (returns parent groups the user is member of)
- it does not include not-active groups.
But if group hierarchy is not needed and only direct memberships are to be considered, this can be done even simpler (at least in my opinion) than all the solutions above:
javascript∶ 'SUBQUERYsys_id,group,sys_user_grmember^user=' + current.variables.crep_owner + '^ENDSUBQUERY^active=true'
*) Note that above the semicolon after keyword javascript is not actually a semicolon (but the Unicode ratio character), so you have to replace it with an actual semicolon if you copy-paste the whole reference qualifier.