What's the issue with nesting?
Nested loops or conditions make your flow progressively more difficult to read and understand. And quite often they are unnecessary. In the case of loops (Apply to each), Power Automate is quite trigger happy and immediately encloses new actions in an Apply to each loop when you access an element of an array. And in the case of conditions, you often only need actions in one branch - but the second (empty) branch still takes up screen real estate. Also important, Power Automate has a nesting limit of 8 levels, not that I expect many of us to run into this limitation. Last but not least, Apply to each loops are painfully slow, especially when variables are written inside the loop. But that's a topic for another post.
What are your options?
- Replacing actions inside your Apply to each loop with Filter and/or Select actions.
- Only need to access the first element in the array? The function first() is a good option (although with some pitfalls...)
- Doing complex things inside your loop? Have you considered encapsulating it in its own child flow?
- Consider using an if() expression instead of a condition
- Use the Terminate action to remove some of the nesting levels, especially while checking for halting conditions ("Does X contain a value? If not -> exit flow")
- Have you considered using a Switch action instead of a nested condition?
- Have you tried adding multiple condition rows to your condition?
Filter and Select actions
first()
Loading a single Dataverse row without first()
a) Load the row based on the unique GUID, using the action "Get a Row by ID". This is guaranteed to return only a single row. If necessary load this GUID using a separate "List Rows" (Dataverse). In the subsequent actions, always refer to the output of "Get a Row by ID" - no first() required!
Loading a single Sharepoint list row without first()?
Conclusion
Let me know, if there's a specific approach that you'd like to hear more about.


No comments:
Post a Comment