- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2023 04:24 AM
Hi there
i have a reference field sys_user_group, i need to populate the user display name in a free text field
I found a script include which is supposed to do it , not sure if its the correct one
getGroupMembers: function() {
var grpID = this.getParameter('sysparm_group');
var memObj = new GlideRecord('sys_user_grmember');
memObj.addQuery('group',grpID);
memObj.query();
var nArray = [];
var vArray = [];
while(memObj.next(){
nArray.push(memObj.user.getDisplayValue().toString();
vArray.push(memObj.getValue("user"));
})
var retValue = nArray.toString() + '|' + vArray.toString();
return vArray;
},
//onchange client script - sys_user_group variable
var grmember = new GlideAjax('restrictduplicateitem');
add.parm('sysparam_name','getGroupMembers');
add.parm('sysparm_gid','newValue');
ga.getXML(callback);
function callback(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue("existing_members", answer);
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2023 02:34 AM
Hi @levino ,
1)Right click on the existing member field
and check read only (so that it will be read only all the time and no one edit
Accept and Hit Helpful if it resolves.
Thank you,
Hemanth
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
07-11-2023 10:52 AM
Hi @levino ,
You need update your script:
here you go:
Script include :
getGroupMembers: function() {
var grpID = this.getParameter('sysparm_gid');
var memObj = new GlideRecord('sys_user_grmember');
memObj.addQuery('group', grpID);
memObj.query();
var nArray = [];
var vArray = [];
while (memObj.next()) {
nArray.push(memObj.user.getDisplayValue().toString());
//vArray.push(memObj.getValue("user"));
}
//var retValue = nArray.toString() + '|' + vArray.toString();
return nArray.toString();
},
Client script:
//Type appropriate comment here, and begin script below
var grmember = new GlideAjax('restrictduplicateitem');
grmember.addParam('sysparm_name', 'getGroupMembers');
grmember.addParam('sysparm_gid', newValue);
grmember.getXML(callback);
function callback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue("existing_members", answer);
}
Script include example :
Client script example on incident:
Result :
Accept and Hit Helpful if it resolves.
Thank you,
Hemanth
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
07-11-2023 09:46 PM
Hi @levino ,
Close the thread by accepting the solution if it works so that if someone wants the same solution they can refer.
Thank you,
Hemanth
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
07-12-2023 01:31 AM
Thanks so Hemanth
work well, just one query how can i set the value to read-only

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2023 02:34 AM
Hi @levino ,
1)Right click on the existing member field
and check read only (so that it will be read only all the time and no one edit
Accept and Hit Helpful if it resolves.
Thank you,
Hemanth
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025