check if the user is in among multiple groups

RudhraKAM
Tera Guru

Hello I have a Requirement were on the catalog item we have a field call "product_user " up on request in the work flow we need to write a if condition to check if the user is among any mentioned 6 groups , if yes then it should go for an approval for a particular user if not no ,,

 

can some one help me with the code 

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

you can try something like this.

 

i am adding one script for one group and you can add other groups to check by adding "OR" || operator.

 

var ourUser = gs.getUser().­getUserByID(current.variables.product_user);
answer = ifScript();

function ifScript()
{
if(­ourUser.­isMemberOf(put group sysid/name in single quote) || ourUser.­isMemberOf(put second group sysid/name in single quote)  || ourUser.­isMemberOf(put third group sysid/name in single quote))
{
return 'yes';
}
return 'no';
}

 

note: you can add as much condition in if block by using || operator to check the group

View solution in original post

6 REPLIES 6

SaiRaviKiran Ak
Giga Guru

You can check using gs.getUser().isMemberOf('assignment_group'); //Give assignment group name

 

 

Thanks Sai 

But where are we checking product_user , we are not validating logged in user , this is some thing like requested on behalf of kind of field 

Hello Kam,

 

use below statement to check product user group.

gs.getUser().getUserByID(current.variables.product_user).isMemberOf("group_sys_id");

 

verify field name for product user.

 

Thanks,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Add script like below:

 

var gr2 = new GlideRecord('sys_user_group');  

 

gr.addEncodedQuery(" add encoded query of all the 6 groups")  

 

gr2.query();  

 

  while (gr2.next()){  

 

      var groupsys = gr2.sys_id;  

 

      gs.log('The GroupSys ' +groupsys);  

 

  }  

 

 

 

var gr = new GlideRecord('sys_user_grmember');  

 

gr.addQuery('group', groupsys);  

 

gr.addQuery('user',current.product_user );    

 

gr.query();  

 

if (gr.next()) {

 

  gs.log('query ran');

 

  gs.log('This person is ' + gr.user + ' is a member');

 

}