- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 08:18 AM
Our users dislike the fact that once they choose a group, they have to select the applicable users one by one rather than a mass selection.
Is there a way to automatically populate the member_list field with ALL users from the chosen group, and they can then filter out?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 09:08 AM
Hi @MBarrott ,
Here you go:
Output:😍
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var member = new GlideAjax("getMembers");
member.addParam("sysparm_name", "userList")
member.addParam("groupid", newValue);
member.getXMLAnswer(output)
function output(result) {
g_form.setValue("u_member_list", result);
}
//Type appropriate comment here, and begin script below
}
var getMembers = Class.create();
getMembers.prototype = Object.extendsObject(AbstractAjaxProcessor, {
userList: function(){
var members="";
var id = this.getParameter("groupid");
var grpMembers = new GlideRecord("sys_user_grmember")
grpMembers.addQuery("group", id);
grpMembers.query();
while(grpMembers.next()){
members+=","+grpMembers.user.toString();
}
return members;
},
type: 'getMembers'
});
Hope this helps!!!
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 08:46 AM
Hello @MBarrott ,
One way to achieve this requirement is, you can create an on-change client script that triggers when the user selects a group. Within this script, you can use GlideAjax to call a function from a script include. Please refer to the following scripts:
//Client Script -
//please replace the variable names
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('GetUsersByGroup');
ga.addParam('sysparm_name', 'getUsers');
ga.addParam('sysparm_groupName', newValue);
ga.getXMLAnswer(function(response) {
var users = response;
g_form.setValue('user_list_field_name', users);
});
//Type appropriate comment here, and begin script below
}
//Script Include
var GetUsersByGroup = Class.create();
GetUsersByGroup.prototype = {
initialize: function() {},
getUsers: function(groupName) {
var users = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group.name', groupName);
gr.query();
while (gr.next()) {
users.push(gr.user.sys_id.toString());
}
return users.join(',');
},
type: 'GetUsersByGroup'
};
If my answer solves your issue, please mark it as Accepted ✔️and Helpful👍 based on the impact.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 09:08 AM
Hi @MBarrott ,
Here you go:
Output:😍
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var member = new GlideAjax("getMembers");
member.addParam("sysparm_name", "userList")
member.addParam("groupid", newValue);
member.getXMLAnswer(output)
function output(result) {
g_form.setValue("u_member_list", result);
}
//Type appropriate comment here, and begin script below
}
var getMembers = Class.create();
getMembers.prototype = Object.extendsObject(AbstractAjaxProcessor, {
userList: function(){
var members="";
var id = this.getParameter("groupid");
var grpMembers = new GlideRecord("sys_user_grmember")
grpMembers.addQuery("group", id);
grpMembers.query();
while(grpMembers.next()){
members+=","+grpMembers.user.toString();
}
return members;
},
type: 'getMembers'
});
Hope this helps!!!
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2024 11:49 AM
Hi @Hemanth M1,
Sorry for being so delayed in responding. I modified your script and field values and it worked perfectly. Greatly appreciate the help.
Accepted as solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 09:34 AM - edited 08-30-2024 01:50 PM
I've tested a client script and script include like @Hemanth M1 's. and it works. Of course you need to update the table name in the client script to your table, and the field names for "Group" and "Member list" shown in his post. Seems the first response here was not tested.