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
Super User
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

8 REPLIES 8
Super User
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

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?

Super User
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...

Super User
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

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 Release Wave 2 Plan

Power Platform 2019 Release Wave 2 Plan

Features releasing from October 2019 through March 2020.

thirdimage

Flow Community User Group Member Badge

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

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Flow Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 188 members 5,360 guests
Please welcome our newest community members: