cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Kevon
Level: Powered On

Apply To Each over Approval Response

I am looking for a solution to an approvals flow.  My scenario is that I am trying to build a voting style approval flow.  The approval type is "Everyone must approve".  I noticed that the outcome of this type of approval is a comma delimited list of approval responses.  So, if I had 5 approvers I could have an outcome of "Approve, Approve, Reject, Approve, Reject" or any combination of approve and reject.  While it is simple to apply an all or none scenario using "Contains" and "Reject", what I am interested in is counting the Approves vs the Rejects and applying an overall approval or rejection based on a simple majority in the case of purely internal affairs, or a two thirds majority in the case of more major...

 

So, I had this thought that I could create an apply to each over the responses, but for the life of me I cannot figure that part out.  The only thing available here is the "Current item" which has no information about what is in it. Is this automatically a "response" type because it's inside an apply to each ??

 

If I could do this in c# it would look like this...

int ayes = 0;

int nays = 0;

foreach (var response in Responses)

{

  if (response.approverResponse == "Approve")

     ayes++;

  else

     nays++;

}

 

Can someone help me model this in Flow?

Snag_2d8077df.png

1 ACCEPTED SOLUTION

Accepted Solutions
Dual Super User
Dual Super User

Re: Apply To Each over Approval Response

Hi @Kevon 

 

Use filter action to get your information (one with Approve other with Reject)

 

expression is 

item()?['approverResponse']

 

Capture.PNG

 

Then use expression length(dynamicontentfilterarray) to get your results (will give you count of approve or reject)

 

Regards,

Reza Dorrani

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

8 REPLIES 8
Dual Super User
Dual Super User

Re: Apply To Each over Approval Response

Hi @Kevon 

 

Use filter action to get your information (one with Approve other with Reject)

 

expression is 

item()?['approverResponse']

 

Capture.PNG

 

Then use expression length(dynamicontentfilterarray) to get your results (will give you count of approve or reject)

 

Regards,

Reza Dorrani

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

Kevon
Level: Powered On

Re: Apply To Each over Approval Response

So this is how I interpret your comment.  The problem I'm having with it is the set variable.  There does not seem to be any output from my filter.  I'm sure I'm doing something wrong, but have no idea what.

 

Snag_2dc085d2.png

Community Support Team
Community Support Team

Re: Apply To Each over Approval Response

Hi @Kevon,

 

You can refer to the following step to reproduce the situation in the C#:Annotation 2019-09-09 145225.png

 

Annotation 2019-09-09 145236.png

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Kevon
Level: Powered On

Re: Apply To Each over Approval Response

This is the condition I finally figured out..  It seems to work.
 
greaterOrEquals(length(body('CountEm')),3)
Kevon
Level: Powered On

Re: Apply To Each over Approval Response

@RezaDorrani 

 

I played around with this a little more because it wasn't behaving as I expected and found one issue. 

 

Using the step "Start and wait for an approval" doesn't work.  The issue is that the flow STOPS the second *anyone* rejects it.  

 

So, how do we create an approval which will wait for ALL responses before progressing?

Dual Super User
Dual Super User

Re: Apply To Each over Approval Response

Hi @Kevon 

 

Select the option for Everyone must approve

Kevon
Level: Powered On

Re: Apply To Each over Approval Response

@RezaDorrani I did that... and that's where the issue is...  with that option, everyone must approve... Flow thinks it's smart and stops the flow as soon as ONE person declines it.

 

I've changed the type of approval to "Custom Responses - Wait for all responses (Premium)" and we'll see if that works...

Dual Super User
Dual Super User

Re: Apply To Each over Approval Response

Hi @Kevon 

 

That is because even if one declines then outcome will be rejected

This is by design - https://docs.microsoft.com/en-us/flow/all-assigned-must-approve

 

Helpful resources

Announcements
firstImage

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

firstImage

Incoming: New and improved badges!

Look out for new contribution recognition badges coming SOON!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Solution Authors
Top Kudoed Authors
Users online (4,864)