Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Triggers
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Resources
  • Get help with flow
Menu

Avoid ‘Apply to each’ after single approval response in Power Automate

Posted on December 20, 2020November 21, 2021 by Tom

“When I use the Power Automate approval action and set it to ‘Approve/Reject – First to Respond’ i still get the ‘Apply to each’ automatically created when i use the output.”

“I have a Power Automate flow that sends an approval request to a single user. When I try to use the output of the Approval (for example the comments they have added) in a subsequent step, ‘Apply to each’ container is added.”


Output of the approval task in Power Automate is always an array of responses. And like every other array in Power Automate, if you want to access the data, you must loop through it. Process each of the objects in the array, one by one, using the ‘Apply to each’ action. It doesn’t matter how many objects the array contains. It can be just one response or 10 responses, important is the returned data type, and that’s an array. But using expressions, there’re other ways to access objects in an array.

First() expression

If it’s an array with only a single object, you can use the first() expression. You input an array as the parameter and it’ll return the first object from that array. And your responses array has only a single object, the first one.

The easiest way to get the array parameter is to actually let the flow add the ‘Apply to each’. It’s the same input, you can take it from there.

Power Automate first expression
e.g. first response from 'Start and wait for an approval' action:
first(outputs('Start_and_wait_for_an_approval')?['body/responses'])

Now you have the first response, but the response is an object with multiple values. It contains all information from the response: approver name, response, comments… Therefore, you must extend the previous expression by adding the desired value.

As before, you can get the value when you use the dynamic content in the flow. It’s the part beginning with the ? that you should add.

Power Automate first expression value
e.g. display name of the approver from the first response:
first(outputs('Start_and_wait_for_an_approval')?['body/responses'])?['responder/displayName']

You’ll need the expression for each value from the response you want to use, no more dynamic contents. The difference when building approval history is shown on the screenshots below. Using dynamic content inside ‘Apply to each’:

power automate approval history dynamic content

Using first() expression to avoid ‘Apply to each’:

power automate approval history first expression

Summary

I’d say avoiding the ‘Apply to each’ action is often a cosmetic topic in Power Automate approval processes. You can use the first() expression instead, but then the response processing part of the flow will be full of expressions, making the flow harder to read and understand.

Using ‘Apply to each’ is +1 loop in the flow. Using the first() expression is -1 loop, but +X expressions. You must decide which approach makes more sense to you.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Do you know what to do, but not how to do it?

Get The Ultimate Power Automate expressions cheat sheet and translate your thoughts into flows with ease!


NEW! Master the HTTP requests to SharePoint with a new cheat sheet!

Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Hello and welcome!

My name is Tom and I'm a business process automation consultant and Microsoft MVP living in the Czech Republic. I’ve been working with Microsoft technologies for almost 10 years, currently using mainly Power Automate, SharePoint, Teams, and the other M365 tools.

I believe that everyone can automate part of their work with the Power Automate platform. You can achieve a lot by "clicking" the flows in the designer, but you can achieve much more if you add a bit of coding knowledge. And that's what this blog is about.

To make the step from no-code Power Automate flows to low-code flows: using basic coding knowledge to build more complex yet more efficient flows to automate more of your daily tasks.

  • Use Power Automate to forward Outlook events upon registrationJanuary 29, 2023
  • Why the condition is false for the same numbers (Power Automate)January 25, 2023
  • How to forward event invitation to other calendar (Power Automate)January 22, 2023
  • Run ‘For selected item’ flow from non-default environment (Power Automate)January 18, 2023
  • Hide button in SharePoint list after Power Automate flow startedJanuary 15, 2023

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2023 Let's POWER Automate | Theme by SuperbThemes