- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 04:50 AM
Hi All,
I have 2 field Members (List Collector) and Group Name (Reference) in a catalog item.
Whenever a requester selects a group so in the Member field the list of users in who is part of that group should populate as options to select.
Kindly, help with the scripting.
Thank you..!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 05:07 AM
something like this in advanced ref qualifier
javascript: var query;
var arr = [];
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("group", current.variables.group_name);
gr.query();
while (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
11-01-2023 05:04 AM
Hi @Rakshanda Kunte ,
On Members field write reference qualifier and use below script
javascript:"sys_idIN" + new scriptIncludeName().scriptIncludeFunctionName(current.variables.group_name);
where "current.variables.group_name" is the way to call the variable that contains the group (update the name "group_name" according to the right name of your variable).
Create new script include with name-
getMembersOfGroup: function(group_name) {
var result = [];
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("group", group_name);
gr.query();
while (gr.next()) {
result.push(gr.getValue("user"));
}
return result.join(",");
}
Please mark it as solution proposed and helpful if it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 05:05 AM
it should show only those users who belong to the selected group?
if yes then you should use advanced ref qualifier
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
11-01-2023 05:07 AM
something like this in advanced ref qualifier
javascript: var query;
var arr = [];
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("group", current.variables.group_name);
gr.query();
while (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
11-01-2023 05:09 AM
You can write script include :
Name : GetGroupMemberUtil
Function Name : groupMembers()
var GetGroupMemberUtil = Class.create();
GetGroupMemberUtil.prototype = {
initialize: function() {},
groupMemebers: function(groupSysId) {
var array = [];
var grMem = new GlideRecord('sys_user_grmember');
grMem.addEncodedQuery("group=" + groupSysId);
// grMem.addQuery('group', groupSysId);
grMem.query();
while (grMem.next()) {
array.push(grMem.user);
}
return "sys_idIN" + array.toString();
},
type: 'GetGroupMemberUtil'
};
& write reference qualifier on List collector field -
javascript: var query = new GetGroupMemberUtil().groupMemebers(current.variables.<your_variable_name>);
query;
Hope this helps...!!
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates