How to check if current user in particular group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-31-2024 10:11 PM
How to check if current user is in particular group if he is not in that group he will be added to that group

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-31-2024 10:23 PM
Hello @Basina Akash,
Please use the below line of code in your server side script to check if user is member of group.
gs.getUser().isMemberOf("Service Desk"); // Service Desk is group name.
If you use above line in if condition, in the else part, you can glide grmember table and add user in it.
Hope this fulfill your requirement. please mark answer helpful.
Thanks you,
Rajesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-31-2024 10:36 PM
how to add user in group

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-08-2024 02:35 AM
Hello @Basina Akash,
Sorry for the late response. Please check the script to add logged user by checking the group.
var grmem = new GlideRecord('sys_user_grmember');
grmem.addQuery('group', 'd625dccec0a8016700a222a0f7900d06'); // group - service desk
grmem.query();
if(grmem.next()){
var cuser = gs.getUserID(); // logged in user.
grmem.user = cuser;
grmem.insert();
gs.info("user added -"+cuser+"into the group"+grmem.group);
}
If you use above line in if condition, in the else part, you can glide grmember table and add user in it.
Hope this fulfill your requirement. please do not forget to mark answer correct and this reply as helpful.
Thanks you,
Rajesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-31-2024 10:23 PM
Hi @Basina Akash ,
Where do u want to validate this?
If in Script Include/Scheduled Job/Business Rule u can use
if(gs.getUser().isMemberOf('<sys id of assignment group>')){
// do nothing
}else{
// create record in sys_user_grmember table
}
Thanks,
Danish