- 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-10-2015 11:48 AM
Ok, we are getting closer! After the last change, one user name was returned from the Physical Security group. The group has nine members.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2015 11:51 AM
Please see my other reply as it will correct this situation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2015 11:51 AM
in the script include
in the while loop use this line instead as suggested by Michael and you will be all set.
user_array.push(getMembers.user + '');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2015 11:47 AM
You are heading down the right path, but there a few tweaks you need to make to your script. Below is a working script include:
var GetGroupMember= Class.create();
GetGroupMember.prototype = {
getMember : function() {
var x = '8a5055c9c61122780043563ef53438e3';
var user_array = [];
var getMembers = new GlideRecord('sys_user_grmember');
getMembers.addQuery('group',x);
getMembers.query();
while(getMembers.next()) {
user_array.push(getMembers.user + '');
}
return 'sys_idIN' + user_array.toString();
}
};
Couple of things to point out that I changed:
- Line 11 - you were pushing the Display Value which is not what you want. The user Display Value is the user's name out of the box and you need to push the user's SysID so I corrected that.
- Line 11 - when pushing SysID's or really any type of string in a array, make sure you put + '' at the end. I have lost many hours of my life in the past with similar situations to find out that there is a pointer issue sometimes in while loops. What happens without this is that only 1 user will show up because the while loop ends up repeating the same SysID over and over again - you can detect this by using gs.log to push the array output to the log. The + '' makes it go back to the server and get the actual value versus pulling it from memory.
Then as Anurag states, the reference qualifier should be: javascript:new GetGroupMember().getMember();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2015 11:53 AM
Many thanks to Anurag and Michael! It works!
Best part is I really learned a lot from both of you! I am most grateful.