How to cancelled Approval group activity using wait for condition based on script

Minal7
Tera Contributor

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.

Minal7_0-1666593173696.png

 

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.

8 REPLIES 8

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.

Thanks. 🙂

Minal
Tera Contributor

I have tried the above for getting the value of counts.approved, counts.cancelled see the below screenshot.

Minal_0-1666686549281.png

I think this script is not correct If you have any other solution for this then please share.

Thanks.

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.

 

Thanks. 🙂

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