How can i collect the combined outputs from a for-each loop in Azure Logic Apps

Herries, Roddy 0 Reputation points
2024-05-20T14:49:22.0933333+00:00

Hi,

I am trying to collect the outputs of a for-each action in my azure logic app. The logic is this:

Send and approval request to each approver (email), then subscribe on a webhook for the approval responses (I do this with a correlation ID outside of the process). Collect the result of all the callbacks (approve or reject). If anyone rejected then the overall decision is reject, otherwise it is approve.

From my reading and experimentation it seems difficult to collect the results in a for-each like this, especially if the for-each runs concurrently due to the lack of any way to safely update shared state between the concurrent activities.

I wondered if there are any solutions/workarounds to this?

Screenshot 2024-05-20 at 15.47.51

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,299 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Eliot Cole 6 Reputation points
    2025-01-09T19:04:30.37+00:00

    I know that this is a very late response to this, but I have two answers for you.

    Before I get to them, this kind of thing would usually need a bit more information / context to be edited into the question. Like, for example, which action is providing the information that you're looking for, and suchlike ... but I'll assume the HTTP Webhook one.

    Answer 1 - Use The Approvals System

    This provides the functionality that you're trying to get out of your emails, and is way easier to leverage in Power Automate / Logic Apps.

    Answer 2 - Use The result() Function

    You should be able to leverage the result() function within a filter action's 'From' field on the 'For each' then filter to the item()?['name'] which matches the action that you'd like to collate information on.

    It should be noted that it only really works scoped actions that are NOT an 'Until' action (I think this is a bug) which will only output the final loop result.

    I will try to bring you a proper 'solution' for this, if I have the time, however a basic solution is:

    User's image

    That second Select action should contain an array that takes data from every looped iteration of the 'HTTP Webhook' action.

    I will attempt to see if I can provide a pastable version of this, as I constructed it very quickly in Power Automate, but appreciate that you'd want it in Logic Apps. If I can do that swiftly, I'll edit this.

    Either way, here are the values used in each of the key fields:

    FilterToHttpWebHookActionsOnlyArrCNST

    Field Value
    From result('For_each_approver')
    Condition Left item()?['name']
    Condition Right HTTP_Webhook

    SelectOnlyCorrelationIdAndDecisionsArrCNST

    Field Value
    From range(0, length(body('FilterToHttpWebHookActionsOnlyArrCNST')[0]?['outputs']))
    Map See Below
    addProperty(
    	addProperty(
    		json('{}'), 
    		'CorrelationId', 
    		body('FilterToHttpWebHookActionsOnlyArrCNST')[0]?['outputs'][item()]?['inputs/body/YourCorrelationIdKeyNameGoesHere']
    	), 
    	'Decision', 
    	body('FilterToHttpWebHookActionsOnlyArrCNST')[0]?['outputs'][item()]?['outputs/body/YourDecisionKeyNameGoesHere']
    )
    

    I have made a lot of guesses above ... but hopefully you can glean that if you replace 'YourCorrelationIdKeyNameGoesHere' with whatever the path to your actual CorrelationId is ... and similar for the output 'YourDecisionKeyNameGoesHere' decision path ... you will have an array of results to play with.Now ... of course ... you also have to prep for errors. ;)

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.