- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2020 01:49 AM
hi,
i have to Check the Groups of an User.
I get the Userinformations from a Field through a GlideRecord
gr.board.owner.getValue()
No i have the SysId but how i can Check the Group or Roles?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2020 02:53 AM
hey hi Please try below:
function test(){var VTBOwner="9da66f651b3333009998da49cc4bcb63";//put VTBowner=grCard.board.owner.getVale();
var gr= new GlideRecord('sys_user_grmember');
gr.addQuery('user', VTBOwner);
gr.query();
while(gr.next()) {
if(gr.group=='0a52d3dcd7011200f2d224837e6103f2')// sys id of group1
{
gs.log('yes');
}
else {
gs.log('no');
}
} }
test();
i have tested it output SS:
tthanks!!
if this helps then please mark if correct and helpful
Regards,
ajay
[ Architect | Certified Professional]
Was this response helpful? If so, please mark it as ✅ Helpful and ✅ Accept as Solution to help others find answers.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2020 01:54 AM
hi Please check this below link it will help you :
https://developer.servicenow.com/app.do#!/api_doc?v=newyork&id=r_GS-hasRoleInGroup_O_O
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2020 02:01 AM
Yes, thanks. But i need a solution to get the Information of GS
I only have the User SYS ID i cant use gs.....
if is use gs. i get the Userinformation of my admin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2020 02:33 AM
Hi
Use below condition in your script:
if(VTBOwner.hasRole('admin') && (VTBOwner.isMemberOf('assginment_group1') || VTBOwner.isMemberOf('assginment_group2'))
Please mark correct and Helpful if it helps
Thanks & Regards
Himanshu Dubey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2020 02:40 AM
Hi,
Below code works for logged in user:
var currentUser = gs.getUser();
gs.info(currentUser.isMemberOf('Capacity Mgmt'));
If we have the user sys_id, isMemberOf() function may be won't work. I tried below, it doesn't work with user sys_id :
var usr= gs.getUserID(); // returns sys_id of the user record
gs.print(usr);
gs.print(usr.isMemberOf('Capacity Mgmt')); // it says undefined
gs.getUser(),Returns a reference to the user object for the current user.
So, your code returns the sys_id of the user record.
May be you can use below:
var VTBOwner=gr.board.owner.getValue(); // assuming it returns user sys_id
var query= 'user='+VTBOwner
+'^group=<<Group sys_id>>' //replace with group sys_id
+'^ORgroup=<<Group sys_id>>'; //replace with group sys_id
var grMem= new GlideRecord('sys_user_grmember);
grMem.addEncodedQuery(query);
if(grMem.next())
{
answer = true;
}
else
answer = false;
If I have answered your question, please mark my response as correct and/or helpful.
Thanks,
Suseela P.