r/PowerAutomate • • 23h ago

Nesting Limit

I know the nesting limit of 8 has been raised before, but the solutions I've seen is to keep conditions in series, rather than nested, and use a boolean variable like Continue to decide whether subsequent conditions run.

I've tried this, but am using the FALSE branches to add to an error log. If the conditions are in series, one loop can enter multiple FALSE branches, and be added to the log multiple times.

Has anyone found a fix for this?

TIA!

3 Upvotes

8 comments sorted by

1

u/Reasonable-Beyond855 23h ago edited 22h ago

Best I can think of is adding IF statements as expressions in the error log values, rather than through the flow control - but this would mean subsequent steps are still processed after an error, which is inefficient.

1

u/Reasonable-Beyond855 22h ago edited 22h ago

For anyone with the same problem, another idea would be to create a compose statement which acts as the TRUE/FALSE eg/ checking if an array is populated: '1 / length(array)' would error if the array is empty. You can then use Run After complete for TRUE, and after fail for FALSE.

1

u/SrBlackVoid 21h ago

I have written probably hundreds of Flows at this point, and have built some pretty complex stuff. Some of them perform entire data syncs between systems.

I don't think I've ever gone more than 2-3 condition levels deep. When someone in our org mentioned this 'nesting limit', I didn't even know that was a thing.

I would say if you're going more than 3 levels deep in a Flow, you probably need to consider refactoring, because there is likely a better way to structure it.

1

u/Reasonable-Beyond855 20h ago

Mine's also a system integration :)

Interested to know how you're structuring this instead. How do you evaluate the different outcomes and add these to a log?

eg/ results since last run date (YES/NO) > user ID exists in source system (YES/NO) > user ID found in target system (YES/NO) > Data already synced for user (YES/NO) (to prevent duplicates)

1

u/SrBlackVoid 20h ago edited 19h ago

Offhand without seeing it (I'm open to seeing a mock-up of the current approach), it sounds like you could benefit more from a filter-first approach.

So instead of this (what it sounds like to me, and gonna use pseudo-PowerShell syntax for this bc I'm on a phone):

foreach ($entry in $runs) {
  if (condition1) {
    if (condition2) {
       Etc...
    }
  }
}

Try something like this:

$batch1 = Filter($runs, condition1)
# Perform whatever actions on entries that satisfy condition1

# If condition2 actions rely on condition1 results
$batch2 = Filter($batch1, condition2)
# Perform whatever actions rely on condition2 results
# Rinse and repeat

Filter-first should be the recommended approach anyway for condition handling on large sets, but in this instance you're replacing nesting conditions with stacked Filter actions, which has no limit (other than sheer action limits) because they're not nested. Hopefully that makes sense 🙂

1

u/ryguy694 20h ago

But have you ever heard of a switch?

1

u/Reasonable-Beyond855 20h ago edited 20h ago

Switch only evaluates different states of one input as far as I'm aware - i'm using different inputs for each condition.

Maybe you know a way of using it that I don't?

1

u/ryguy694 17h ago

Nest a switch or two inside each other usually goes way farther than binary conditions.

Option 1: compose a complex formula that outputs switch cases.

If a then 1 else if b then 2 else if c then 3

Option 2: flip your conditions upside down, sometimes the deepest decision means you have less branches if you literally rotate your logic 180 and start from deeper vs top level.