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

“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.

power automate approval history dynamic content
using dynamic content inside ‘Apply to each’
power automate approval history first expression
using first() expression to avoid ‘Apply to each’

Summary

I’d say avoiding the ‘Apply to each’ action is more of a cosmetic topic. 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.

Add a Comment

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