- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2022 03:13 PM
Hi All,
I may be overthinking this but would like some input.
I have a scenario where on a catalog item, I have a reference variable to the sys_user table. Based off of the user that gets selected, i'd like it to display in a Multi Line Box (or maybe there is a better way) to list all of the groups that selected user is a member of (from the sys_user_grmember table)
Here is my current solution and it's almost there but i'm needing some help.
Have two variables
Reference variable called mirror
Multi line box called groups
OnChange catalog script it goes and fetches information from the sys_user_grmember table
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var groups = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user',newValue);
gr.query();
while(gr.next())
{
groups.push(gr.group);
}
g_form.setValue('groups',groups);
}
I can only get it to output the sysids of the groups (i have set the display name on the table to return the group name, to no luck that hasn't helped)
Is there a better way in the onchange script to build in getting the values of those sysIDs, or do i need another script to convert them?
Or is there a much better way to accomplish this.
Thanks!
Solved! Go to Solution.
- Labels:
-
Service Catalog
-
Service Desk

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 02:58 PM
Ok so I decided to change this a little and go with a client callable script include that will work in both Service Portal, mobile, as well as the standard interface.
1. Created a script include called GroupsMembership. When you go to create it remember to check client callable. script below.
var GroupsMembership = Class.create();
GroupsMembership.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getGroups: function() {
var groups = [];
var user = this.getParameter('sysparm_userID');
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', user);
gr.query();
while (gr.next()) {
groups.push(gr.group.getDisplayValue());
}
return groups.toString();
},
type: 'GroupsMembership'
});
2. Updated client script using glideajax. script below.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var gajax = new GlideAjax('GroupsMembership');
gajax.addParam('sysparm_name','getGroups');
gajax.addParam('sysparm_userID', newValue);
gajax.getXML(getResults);
}
function getResults(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('groups', answer);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2022 03:33 PM
On your group.push do gr.group.getDisplayValue();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2022 06:42 PM
Hi Brian thanks for the reply.
Are there any other changes needed to get that to work?
Changing
groups.push(gr.group);
to
group.push(gr.group.getDisplayValue();
that unfortunately didn't have success for me. Adding that, the group field seems to not populate anything with that on my catalog item.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 08:05 AM
It should be group.push(gr.group.getDisplayValue()); Looks like you were missing an end perenties. Note that this code will now work in the Service Portal if you are using it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 09:31 AM
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var groups = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user',newValue);
gr.query();
while(gr.next())
{
group.push(gr.group.getDisplayValue());
}
g_form.setValue('groups',groups);
}
Still seeing blank groups.
I double checked that table and i do have a display value set