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 08:41 AM
Hi @Ryan Bader ,
I think the issue is with GlideAjax Util call
Instead of using the Name you should use the API Name while calling in GlideAjax
e.g.
var ga = new GlideAjax('global.ABCUtilGlobal');
ga.addParam('sysparm_name', 'getITBusinessIntelligenceUsers');
ga.getXML(callback);
This might solve your issue. Please mark the correct answer if this solve your issue
Regards,
Amol Bavaskar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-23-2025 08:56 AM
Hi @Ryan Bader ,
I have change the script include and instead adding options call the script include in dynamic 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.sys_id.toString());
}
queryStr = conditions.join('^OR');
return queryStr;
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Hasan Mohammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-23-2025 09:07 AM
all snc_internal users should have read access to sys_user_grmember table
Did you create choice variable for this? If yes then this is not recommended.
What if group has 15/20 users, it would create those many choices
Are you saying by default when catalog form loads the members of this group should be shown?
If yes then you should have reference variable to sys_user and have this in advanced ref qualifier
javascript: var query; var arr = [];
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("group.name", "IT Business Intelligence");
gr.query();
if (gr.next()) {
arr.push(gr.getValue('user'));
}
query = 'sys_idIN' + arr.toString();
query;
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-24-2025 12:45 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader