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 01:40 PM
GlideRecords in client scripts are not supported nor recommended. Use Glide Ajax to run the query on the server and return the desired values. Here is an excellent guide if you are not familiar.
You'll want to be more specific in your GlideRecord in the Script Include so as not to return every group and member, unless that's what you really want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2023 01:47 PM
Hi Brad
thank you for your reply, just to be simple i didn't put addQuery .
Also , thank you for the glideAjax guide,
If you can tell me how to get the name of group and member usernames it will be great as it is urgent to deliver this script
thank you again
Nabil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2023 01:58 PM
Hello @Nabil EL FILALI
Can you test with below code and let me know if it works for you:
Script Include:
// Name: GroupMembersHelper
var GroupMembersHelper = Class.create();
GroupMembersHelper.prototype = {
initialize: function() {
},
getGroupMembers: function() {
var result = [];
var sys_user_groupGrMembersGR = new GlideRecord("sys_user_grmember");
sys_user_groupGrMembersGR.query();
while (sys_user_groupGrMembersGR.next()) {
result.push({
group: sys_user_groupGrMembersGR.group.getDisplayValue(),
user: sys_user_groupGrMembersGR.user.getDisplayValue()
});
}
return result;
},
type: 'GroupMembersHelper'
};
Client script:
// Name: YourCatalogClientScript
function onLoad() {
// Instantiate the Script Include
var helper = new GroupMembersHelper();
// Get the group members
var groupMembers = helper.getGroupMembers();
// Display the results
for (var i = 0; i < groupMembers.length; i++) {
alert(groupMembers[i].group + ' ' + groupMembers[i].user);
}
}
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Regards,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2023 11:03 PM
As suggested by fellow community members it is not advisable to use Server Side API i client scripts.
To get the name you can use below-
sys_user_groupGrMembersGR.group.getDisplayValue()
Thanks and Regards,
Saurabh Gupta