Skipping an Approval in workflow

Maxy691
Tera Contributor

Good Afternoon,

I have a requirement to skip the approval if the Requested For is a member of 1 of 2 groups.  I have tried 2 different scripts in a If action in the workflow.  Here is the workflow:

Maxy691_0-1696356046222.png

 

Here are the 2 versions of the script:


answer = ifScript();

function ifScript() {

//var isMember = gs.getUser().getUserByID(current.variables.user + '').isMemberOf('Group Name' && 'Group Name');
var isMember = gs.getUser().getUserByID(current.variables.user + '').isMemberOf('Group Name' || 'Group Name');
if (isMember)
return 'yes';
else
return 'no';
}

**Note I tried both var isMember contexts with the workflow requiring an approval each time the approval task is still created.

 

Not sure what the issue is, no errors or anything, just fails to return yes.

2 REPLIES 2

Tony Chatfield1
Kilo Patron

Hi, ismemberOf() method takes only 1 group as a parameter.
GlideUser | ServiceNow Developers
So based on your post, you would need to check each group as a
separate condition.
Untested but maybe something like this.

 

var isMember = gs.getUser().getUserByID(current.variables.user + '');

if(isMember.isMemberOf('Group1') == true ||  isMember.isMemberOf('Group2') == true) {
return 'yes';
}

 

Uncle Rob
Kilo Patron

Have you used background scripts to validate that this script will output what you hope it outputs?