Catalog client script : how can i get group.name from GlideRecord object ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2023 01:31 PM
Hello
Please need your help on a catalog client scripting :
in fact, the alert below displays the sys_id of group record, actually I need to display just the name of the group and every username related to this group.
thank you !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2023 09:00 PM
Hi @Nabil EL FILALI , I am in agreement with @Brad Bowman that, its not recommended to use the Glide Record in client scripts. Please refer to the @Aniket Chavan Glide Ajax script to get the display value of the reference type fields.
Regards,
Sunil

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2023 03:32 AM
@Nabil EL FILALI GideRecord queries inside the client script is a strict no-no in ServiceNow. Instead as suggested by others, you should use GlideAjax instead.
Following changes need to be done to achieve this. First create a client callable script include as follows.
Here is the script for the script include.
var MyUtils = Class.create();
MyUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getGroupAndGroupMembers: function() {
var groupDetailArray = [];
var grMember = new GlideRecord('sys_user_grmember');
grMember.query();
while (grMember.next()) {
// Build the payload. You can return additional data if needed.
var result = {
"group_name": grMember.group.getDisplayValue(),
"group_member_name": grMember.user.getDisplayValue()
};
groupDetailArray.push(result);
}
return JSON.stringify(groupDetailArray);
},
type: 'MyUtils'
});
Here is how your client script should look.
// client script – contains onLoad function and a callback function
function onLoad() {
var ga = new GlideAjax('MyUtils'); // MyUtils is the script include name
ga.addParam('sysparm_name', 'getGroupAndGroupMembers'); // getGroupAndGroupMembers is the function in the
ga.getXMLAnswer(groupDetailParse);
}
// callback function for returning the result from the script include
function groupDetailParse(response) {
var groupDetail = response.responseXML.documentElement.getAttribute("answer");
alert(groupDetail);
}
Hope this helps.