- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2023 04:17 AM
I have sys_id of a user and I need to get the list of groups in which the is user present.
I need to achieve this via Script.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2023 04:37 AM
Hi @Hrishabh Kumar ,
Hope you are doing well.
Please try below code -
var getGroup = new GlideRecord("sys_user_grmember");
getGroup.addQuery("user","user sys_id");
getGroup.query();
gs.log(getGroup.getRowCount());
while(getGroup.next()){
gs.log(getGroup.group.name);
}
Please mark this response as correct or helpful if it assisted you with your question.
Regards,
Harshal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2023 04:37 AM
Hi @Hrishabh Kumar ,
Hope you are doing well.
Please try below code -
var getGroup = new GlideRecord("sys_user_grmember");
getGroup.addQuery("user","user sys_id");
getGroup.query();
gs.log(getGroup.getRowCount());
while(getGroup.next()){
gs.log(getGroup.group.name);
}
Please mark this response as correct or helpful if it assisted you with your question.
Regards,
Harshal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2023 05:30 AM
Thanks a lot!
This was exactly what I was looking for.
Does it also gets the groups in which the user is manager?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2023 06:04 AM
Hi @Hrishabh Kumar ,
If you want to get groups in which the user is manager
It will be easily done by querying sys_user_group table
var getGroup = new GlideRecord("sys_user_group");
getGroup.addQuery("manager","user sys id");
getGroup.query();
gs.log(getGroup.getRowCount());
while(getGroup.next()){
gs.log(getGroup.name);
}
Please mark this response as correct or helpful if it assisted you with your question.
Regards,
Harshal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2023 11:26 PM
Thanks for the accurate solution.