- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2023 04:17 AM
Hello All,
I created a custom field called "Special Group".
Field type "List":
Reference to "sys_user" table
In that field we need to show only a particular group members.
I written Script include like this:
var GetUsersOfGroup = Class.create();
GetUsersOfGroup.prototype = {
initialize: function() {
},
getUsersFromAppEngineAdminsGroup: function() {
var userList = [];
var groupGr = new GlideRecord('sys_user_grmember');
groupGr.addEncodedQuery('group=477a05d153013010b846ddeeff7b1225');// sys_id of App Engine Admins group
groupGr.query();
while (groupGr.next()) {
var user = new GlideRecord('sys_user');
if (user.get(groupGr.user)) {
userList.push(user.name.toString()); // Assuming name is used as the reference field
}
}
return userList;
},
type: 'GetUsersOfGroup'
};
how should i call this in that field "Special group" reference qualifier so that only
Please correct me if i did anything wrong.
2. In the list it showing sys_id's, how should we show user "names instead of sys_ids"?
@Ankur Bawiskar @SANDEEP28 @Community Alums
Thanks,
Abdul
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2023 04:34 AM
update script include as this
var GetUsersOfGroup = Class.create();
GetUsersOfGroup.prototype = {
initialize: function() {
},
getUsersFromAppEngineAdminsGroup: function() {
var userList = [];
var groupGr = new GlideRecord('sys_user_grmember');
groupGr.addEncodedQuery('group=477a05d153013010b846ddeeff7b1225');// sys_id of App Engine Admins group
groupGr.query();
while (groupGr.next()) {
userList.push(groupGr.getValue('user'));
}
return 'sys_idIN' + userList.toString();
},
type: 'GetUsersOfGroup'
};
Call it like this from the advanced ref qualifier
javascript: new GetUsersOfGroup().getUsersFromAppEngineAdminsGroup();
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
12-04-2023 04:34 AM
update script include as this
var GetUsersOfGroup = Class.create();
GetUsersOfGroup.prototype = {
initialize: function() {
},
getUsersFromAppEngineAdminsGroup: function() {
var userList = [];
var groupGr = new GlideRecord('sys_user_grmember');
groupGr.addEncodedQuery('group=477a05d153013010b846ddeeff7b1225');// sys_id of App Engine Admins group
groupGr.query();
while (groupGr.next()) {
userList.push(groupGr.getValue('user'));
}
return 'sys_idIN' + userList.toString();
},
type: 'GetUsersOfGroup'
};
Call it like this from the advanced ref qualifier
javascript: new GetUsersOfGroup().getUsersFromAppEngineAdminsGroup();
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
12-04-2023 04:43 AM
Hi @Abdul333 ,
I trust you are doing great.
Reference qualifier :
javascript:new GetUsersOfGroup().getUsersFromAppEngineAdminsGroup();
The updated Script Include should look like this:
var GetUsersOfGroup = Class.create();
GetUsersOfGroup.prototype = {
initialize: function() {
},
getUsersFromAppEngineAdminsGroup: function() {
var userList = [];
var groupGr = new GlideRecord('sys_user_grmember');
groupGr.addEncodedQuery('group=477a05d153013010b846ddeeff7b1225'); // sys_id of App Engine Admins group
groupGr.query();
while (groupGr.next()) {
var user = new GlideRecord('sys_user');
if (user.get(groupGr.user)) {
userList.push(user.name.toString()); // Assuming name is used as the reference field
}
}
return 'nameIN' + userList.join(','); // Changed sys_idIN to nameIN and array to comma-separated string
},
type: 'GetUsersOfGroup'
};
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2023 05:56 AM - edited 12-04-2023 05:57 AM
@Amit Gujarathi @Ankur Bawiskar I added the query in Advanced reference qualifier but after saving it's again changed to simple, how should we fix this?
Thanks,
Abdul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2023 06:04 AM
ensure you give : and not : in the advanced ref qualifier
I think there is a bug in community if we add : it gets converted to : automatically
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