I only intentionally added one Apply to Each, but when I selected “Message ID”, it automatically added the nested one. It seems like the the UI thinks that the Message ID is an iterable. When this flow ran, it gave me an error (sorry, the exact step names are different because the above is a recreation):
“ExpressionEvaluationFailed. The execution of template action 'Apply_to_each' failed: the result of the evaluation of 'foreach' expression '@items('Apply_to_each_2')?['id']' is of type 'String'. The result must be a valid array.”
When I was creating the flow, I was suspicious of the nested apply to each. I knew that the Message ID was a string and not an array. And then when the flow finally triggered later, I got that exact error back!
Why does the system automatically create this extra nested flow? When I was creating the Apply to Each, I selected the Message ID. I know that the Message ID is a member of an item within an Array. Since I want to access that member from multiple steps in the loop, the following makes more sense. Why doesn’t the system just do that for me instead of the weird nested loops thing?
Apply to each + compose makes a lot more sense for this. Can someone explain why the automatic behavior is to use nested loops?