- 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
02-26-2019 01:42 PM
Hi There,
Has anyone had any success using this BR in a custom application scope? I am trying to use it in a custom app I created, but I'm not having any luck. When I add the BR and the reference qualifier, my reference list still shows all of the sys_users unfiltered
I created a new Business Rule - I have the BR set to run "before" on insert and update.
Under Advanced, I added your above script:
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;
}
And then on the field I use as a reference, I added this reference qualifier:
Now, for some context. I am trying to display only users who are a member of the "Hiring Managers" group. But when I add this RQ, I still see all of the users when I do a lookup on my field. The group was created in my dev environment, outside of the custom app I am building, could that be the case?
I tried changing the name of the group in the RQ to "hiring managers" or "hiring_managers" but have not had any luck.
Here's the group just for kicks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2019 05:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2019 10:51 AM
This was extremely helpful and, quite honestly, ServiceNow should have included this with or instead of the version for Roles!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2019 05:33 PM
Hello,
I deployed that bit I wrote as a global Business Rule, but the "When to run" tab isn't filled in. No filters, nothing is ticked - when I created the BR, I simply ignored the tab and filled in the code in the "Advanced" tab. For reference, this is exactly how the original BR I copied from looks like -- in your instance, find the BR named "getRoledUsers", it should have an update date of "30/10/2009 23:30:30" and updated by "pat.casey".
Your reference's qualifiers look alright - nearly identical to my own except for the different group name. My BR function name does have a prefix though, it's "my_getGroupedUsers" instead of just "getGroupedUsers", and the Reference qualifier javascript is also updated to match. I tend to add a prefix to all my stuff, helps when you're quickly skimming through code. Shouldn't matter though, I don't think there's an existing "getGroupedUsers" anyway.
Try emptying your "When to run" tab (remove any filters and uncheck whatever). Again, for reference, look at the existing "getRoledUsers" global Business Rule.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2020 10:10 AM
Hello All,
I was trying to apply this solution too on my personal instance but when I created the script include under the GRC:Vendor Risk Management it didnt working. I decided to create the script include in the Global application, but by doing that, I got a different result, which was the error message:
I was able to fix my issue just by adding global on the qualifier field:
javascript:new global.GetGroupMember().getMember('group_sysID');
and with this configuration on the script include:
Name: GetGroupMember
API Name(read-only): global.GetGroupMember
Client callable: true
Application: Global
Active:true
Accessible: All application scopes (important if you want any application to use it like in my case was GRC:Vendor Risk Management trying to access it)
If for some reason, you select "This application scope only" in the Accessible from field, you will get this errir instead:
I know this may sound a little like common sense, but Im hoping this is intended for those like the author and myself, that doesn't know a lot of scripting and we are still learning.
Thank you all for your posts that helped me get it working for my need.