- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2022 08:04 AM
Hello,
I am creating a business rule in which I need to check if current logged in user is member of any of the child groups of a certain parent group.
And if user is a member of any of them groups, then code can continue and display the appropiate message.
How can I achieve this please. need code help
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2022 08:09 AM
Hello
you can try this
var arr=[];
var gr = new GlideRecord('sys_user_group');
gr.addQuery('parent','your_parrent_group_sys_id');
gr.query();
while(gr.next())
{
arr.push(gr.name.toString());
}
for(var i=0; i<arr.length; i++)
{
if(gs.getUser().isMemberOf(arr[i]))
{
//continue your code
}
}
PLEASE MARK MY ANSWER CORRECT IF IT HELPS YOU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2022 08:21 AM
Hi,
you can get first all the child groups of the parent and then query sys_user_grmember
var arr = [];
var gr = new GlideRecord("sys_user_group");
gr.addQuery("parent.name", "Group ABC");
gr.query();
while (gr.next()) {
arr.push(gr.getValue('name'));
}
var gr1 = new GlideRecord("sys_user_grmember");
gr1.addQuery("group", "IN", arr.toString());
gr1.setLimit(1);
gr1.query();
if (gr1.hasNext()) {
// member of any one of the child groups
}
regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader