WF Group Approval Activity results

YenGar
Mega Sage

Hi Community,

Is there a way to set the result of a group approval in the workflow based on the amount of results by individuals?

For example: If an approval is assigned to a group that contains 5 people, and all of them must take an action (approve or reject). Let's say that 3 users approve and 2 user reject, then the result should be 'approved'. Meaning that whatever action taken combined is greater, that should be the result of the activity but all users must be taken into consideration.

I've looked at the Percentage based approval solution (https://www.servicenowguru.com/graphical-workflow/approval-percentage/ )that Mark Stanger has but I don't think that would achieve what I'm trying to do. I would like all users to take an action and then set the activity result based on what was greater, either approve or reject.

Is this possible? And if so, can you provide some guidance on how to get it done?

Any suggestion is truly appreciated!

Thank you,

Yeny

7 REPLIES 7

EashVerma
Giga Expert

Hello Yeny,



For the Approval Activity in the workflow, you can set the "Wait For" field to "Condition based on Script" and use the following script.



if(counts.requested == 0){


var approvePercent = 50;


if(counts.approved > counts.rejected){


    answer = 'approved';


}


else


    answer = 'rejected';


}



Through this, the script will run when all the users have provided the approval as approved/rejected.



Please, mark if the answer is helpful.


Hi Eash,



Thank you! I tried the script but for some reason it is not ending the activity, it stills keeps running even after all the approval requests have been completed and I can't get it to end and move over to the next workflow activity .



I also tried it a different way but no luck either.


var approveCount = 0;


var approvePercent = 100;


if(approveCount == counts.total){


if(counts.approved > counts.rejected){


    answer = 'approved';


}


else


    answer = 'rejected';


}



Any ideas?



Yeny


EashVerma
Giga Expert

Having the condition if(counts.requested == 0) completes the currently running activity. I tried working it on my demo instance.



find_real_file.png



find_real_file.png


Try keeping in logs to check if the flow goes inside the if loop when all the requests have been responded.



You can also change the first if condition to:


Option 1 : counts.total == counts.approved + counts.rejected


Option 2 : counts.total - counts.requested == 0



Let me know if you could navigate through.



I have to be doing something wrong then because it still isn't working for me.



This is what I have-


workflow script:


approval.PNG



Approvals completed:


approvers.PNG



Workflow still saying 'state: Running' on activity


workflow.PNG



I tried the other options you suggested and still got the same result. I'm going to continue playing with the script