How to cancelled Approval group activity using wait for condition based on script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2022 11:37 PM
I have added cancelled condition in the Approval group activity and I have cancelled the approval through the scheduled job but the approval takes approve and the next activity is run.
so i need to script for cancelling the Approval group activity.
I have try to below code but it is not work
if (counts.approved != 0) {
answer = 'approved';
} else if (counts.rejected =! 0) {
answer = 'rejected';
} else if (counts.cancelled !=0) {
answer = 'cancelled';
}
Thanks for any help.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2022 09:49 PM
Can you please try adding a runscript activity before approval activity and in that put following:
gs.info('Approvals Check Approved: '+ counts.approved);
gs.info('Approvals Check Rejected: '+ counts.rejected);
gs.info('Approvals Check Cancelled: '+ counts.cancelled);
To understand what is going wrong with the approval activity, we must know what values are coming in the above variables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2022 01:32 AM
I have tried the above for getting the value of counts.approved, counts.cancelled see the below screenshot.
I think this script is not correct If you have any other solution for this then please share.
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2022 02:46 AM
Here is the problem in line 3.
You can see in the logs that approved records number is more than 0 and hence your first condition is getting satisfied.
"if (counts.approved != 0) { answer = 'approved'; }"
Hence your flow was propagating with approved.
As the first condition is satisfied the script wont evaluate the "else" part.
You will have to modify your script according to your requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2022 02:52 AM
The group approval is approved or rejected based on the user approvals, according to the logic specified in the Wait For field.
Results
The workflow designer can assign a result value using activity.result from within a script field of the activity. By default, the result value is the final approval disposition. This disposition depends on the approval actions take by the approvers and the approval conditions specified in the Wait for or When Anyone Rejects fields. Possible result values are:
Approved
Rejected
Deleted
Cancelled
Regards,
Rachel Gomez