- 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:32 PM
Try below script:
var gr2 = new GlideRecord('sys_user_group');
gr2.addEncodedQuery(" add encoded query of all the 6 groups");
gr2.query();
while(gr2.next())
{
var groupsys = gr2.sys_id;
gs.addInfoMessage(sys +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');

- 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