Skipping an Approval in workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 11:19 AM
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:
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 04:27 PM - edited 10-03-2023 04:28 PM
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';
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 04:55 PM
Have you used background scripts to validate that this script will output what you hope it outputs?