- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2015 08:32 AM
Hi,
I have a reference variable called "Project Lead". I want to only show members of the Physical Security group in this field. From what I've read it seems a reference qualifier should be used. After reading some articles I tried entering the following:
Reference qualifier: javascript:new GetGroupMember().getMember(bb3fc3056f68e10006a8f00dba3ee483)
I'm passing the sys_id of the Physical Security group.
Script Include:
var GetGroupMember= Class.create();
GetGroupMember.prototype = {
getMember : function(bb3fc3056f68e10006a8f00dba3ee483)
{
var user_array = [];
var getMembers = new GlideRecord('sys_user_grmember');
getMembers.addQuery('group',bb3fc3056f68e10006a8f00dba3ee483);
getMembers.query();
while(getMembers.next())
{
user_array.push(getMembers.getValue('users'));
}
return 'sys_idIN' + user_array.toString();
}
};
What happens is I get the entire sys_user table unfiltered. How do I just get the members of the Physical Security group so I can select one of them?
Any help is appreciated, as I am new to scripting.
Thanks,
Laurie
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2015 11:51 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2016 06:36 AM
Thanks for this answer, it has solved my issue and I have learned about how to pass parametr to server
/Petr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2017 01:44 AM
Sorry for bumping an older thread, but this may help others searching who also ended up here.
There's an out of the box Business Rule named "getRoledUsers" which returns users matched to (specific) roles, and you can even exclude rather than include. I made a copy of that BR which works on groups instead of roles, so it achieves what the op was looking for with more flexibility - i.e. you can specify multiple groups, and exclude instead of include.
How do you specify code tags? I'll just change the font. Copy the following code and save it in a new Business Rule, say, "getGroupedUsers".
function getGroupedUsers(queryCondition, groupList) {
var groupListIds;
if (queryCondition && groupList) { groupListIds = getGroupListIds(groupList); }
var users = {};
var gr = new GlideRecord('sys_user_grmember');
if (groupListIds) { gr.addQuery('group', queryCondition, groupListIds); }
gr.query();
while (gr.next()) { users[gr.user.toString()] = true; }
var ids = [];
for (var id in users) { ids.push(id); }
return ids;
}
// get sys_ids for the named groups
function getGroupListIds(groupList) {
var ids = [];
var gr = new GlideRecord('sys_user_group');
gr.addQuery('name','IN',groupList);
gr.query();
while (gr.next()) { ids.push(gr.sys_id.toString()); }
return ids;
}
That's it. To use it just supply the appropriate javascript in your reference field's reference qualifier, like so:
javascript:"sys_idIN"+getGroupedUsers("IN","group_name").join(",")
Substitute your actual group names for the second parameter. You can verify this code yourself by looking at the original Business Rule, I only changed the references from roles to groups and removed some spacing. Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2018 12:29 PM
Hello, I know this is an old thread, but I was glad to find it, and it worked well for me. I have a question though, how would I filter where user Active=True?
Many thanks, Mark S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2018 06:02 PM
Hello,
No problem, that just means adding an additional query condition for Active=True.
Ok let's see... the code up there is looking through "sys_user_grmember", so we'll need to dotwalk to "sys_user" to get at the "Active" property you want. This appears to be achieved through the "user" property in "sys_user_grmember", which is a reference to sys_user. Great, just one step.
All you have to do is add the following condition:
gr.addQuery('user.active',true);
Insert this before the gr.query() call, that's it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2018 02:18 PM
Thanks for the reply, did the job for me. Have a good day.