To check user belongs to a group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2018 04:48 AM
Script to check if the logged in user belongs to any one of the groups?( Not a specific group, any one of the group)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2018 05:04 AM
Hi
You need to write a Script Include on sys_user_grmember from where you will return the sys_id's of the group of logged in user.
var usersysid = this.getParameter("sysparm_usersysID");// fetch sysid here
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("user",usersysid);
gr.query();
while(gr.next())
{
gs.print("User is in group::"+gr.group.getDisplayValue());//collect the groups here in an array and return them.
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2018 05:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2018 05:07 AM
If you want this to check for a particular record in table, then create a BR on that table and use below script:
var group = current.assignment_group;
if(!gs.getUser().isMemberOf(group.toString())) {
//Add your action
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2018 05:07 AM
You can query the sys_user_grmember table to get that data. Where are you triggering this? on the incident form?
checkGroups();
function checkGroups(){
var arr = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', gs.getUserID());
gr.query();
while(gr.next()){
arr.push(gr.group.getDisplayValue());
}
gs.log('user is a member of these groups: ' = arr);
}