How to check if user is member of one of the groups from a parent group

Khalnayak
Tera Guru

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

1 ACCEPTED SOLUTION

Mohith Devatte
Tera Sage
Tera Sage

Hello @Khalnayak ,

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

View solution in original post

5 REPLIES 5

Muhammad Khan
Mega Sage
Mega Sage

Hi Khalnayak,

 

For this requirement you can utilize gs.getUser().isMemberOf('<sys_id_of_group>')

It is up to you, whether you use this multiple times in condition of business rule or call a script include in the condition.

 

Hopefully, this will help you.

I need to check if user is member of the child groups for a parent group.

will isMemberOf check if user is member of that group or any nested groups too?

It will only check for a group for which you have specified the sys_id. If you already know the child groups, then you can use their sys_id in the above function.

Mohith Devatte
Tera Sage
Tera Sage

Hello @Khalnayak ,

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