Gather list of users from the sys_user_grmember table for a specific group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-23-2025 08:09 AM
I am attempting to gather a list of users that are in my IT Business Intelligence group to be selected from in a catalog item. originally, I simply used a reference variable on the sys_user_grmember table with the criteria that they were part of the IT Business Intelligence group. the only problem is that not everyone has read rights to sys_user_grmember table. So, I created a catalog client script that references a script include, but I am running into issues, I get and error in the portal (There is a JavaScript error in your browser console). the following is the client script, and the script include. I would appreciate help fixing this or another solution would also be helpful.
client script:
function onLoad() {
var ga = new GlideAjax('EntClientUtils');
ga.addParam('sysparm_name', 'getITBusinessIntelligenceUsers');
ga.getXML(callback);
function callback(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
var answerArr = answer.split(',');
for (var i = 0; i < answerArr.length; i++) {
g_form.addOption('Q1', answerArr[i], answerArr[i]);
}
}
}
part of script include named EntClientUtils
getITBusinessIntelligenceUsers: function() {
var usersArr = [];
var groupSysId = '54e044bd9709e550697c71c71153af1f';
var userGR = new GlideRecord('sys_user_grmember');
userGR.addQuery('group', groupSysId); // Query for the specific group sys_id
//userGR.orderBy('user.name'); // Order by user name
userGR.query();
while (userGR.next()) {
var userName = userGR.user.name.toString();
usersArr.push(userName);
}
return groupsArr.toString();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-23-2025 09:17 AM
Hi @Ryan Bader ,
I have change the script include and instead adding options call the script include in advanced reference qualilfier of reference variable ,Which is present in "Type Specifications" section.
getITBusinessIntelligenceUsers: function() {
var queryStr = '';
var groupSysId = '54e044bd9709e550697c71c71153af1f';
var userGR = new GlideRecord('sys_user_grmember');
userGR.addQuery('group', groupSysId);
userGR.query();
var conditions = [];
while (userGR.next()) {
conditions.push('sys_id=' + userGR.user);
}
queryStr = conditions.join('^OR');
return queryStr;
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
@HasanM