- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2018 01:01 PM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2018 01:26 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2018 01:05 PM
You can check using gs.getUser().isMemberOf('assignment_group'); //Give assignment group name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2018 01:19 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2018 01:27 PM
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
Thank you,
Ali

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2018 01:28 PM
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');
}