- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2018 01:30 AM
I need to access "sys_user_grmember" table for user being part of a specific group, if so return the user and match requested_for user.
I'm having problem when a user is part of multiple groups, then the script only checks for first group and returns false.
need help for a recursive search and return true if he is part of mentioned group.
*********************************************************************************************
answer = ifScript();
function ifScript() {
var usr=current.variables.requested_for;
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', usr);
gr.query();
while(gr.next())
{
var director = gr.u_director;
gs.log("the Group name" + gr.getDisplayValue('group'));
gs.log("Is director true or false" + director );
if(gr.getDisplayValue('group') == 'Director Group' && director == 'true')
{
return 'yes';
}
return 'no';
}
}
Regards
Arjun
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2018 01:57 AM
Hi Arjun,
Can you try the following script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2018 01:57 AM
Hi Arjun,
Can you try the following script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2018 02:43 AM
Hi Ishan,
Thanks for the help on this,
As I'm new to ServiceNow it will be very helpful if you kindly help with this part of the query,
gr.addEncodedQuery('user='+usr+'^group.name=Director Group');
Regards
Arjun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2018 03:08 AM
Hi Arjun,
What help do you need from that line of the code ?
If you mean helping you understand - it does the following
The addEncodedQuery basically builds up the filter that you would like to apply on the glide record (table).
the two attributes that you have on the group membership table are
1) user 2) group
you want that the requested for user must be member of a particular group (Director group) and if it is true then return yes
so in this we are building that query
'user=' --> is the attribute on the membership table.
+usr+ --> dynamic value of the requested for user value.
'group.name=Director Group' --> search for the group name value (exact match with Director Group) value.
Thanks
Ishan Parikh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2018 02:43 AM
Hi
Please try the below script :-
var arr=[];
var usr=current.variables.requested_for;
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', usr);
gr.query();
while(gr.next())
{
arr.push(gr.sys_id.toString());
}
for(var j=0;j<arr.length;j++)
{
checkForEveryGroup(arr[j]);
}
function checkForEveryGroup(eachGroup)
{
//here check your condition
//each group has now the groups in which the user is in. It will call this function for every iteration and do you checkinng.
}