DEV Community

Cover image for What Not to do in Power Automate
david wyatt
david wyatt

Posted on

What Not to do in Power Automate

There are loads of great blogs sharing what to do to be a great Power Automate developer. But that made me think, I've never seen any on what not to do, so I thought I would share my top 10 things not to do in Power Automate.

Before I start, this is my opinion so don't take it personal if you do do these (in fact if you do you could take it as a complement, I've been known to be wrong a lot in the past 😎).

I've grouped them into 3 levels: Basic, Advanced, Master, with it getting more controversial as go up the levels.

Basic

Set variable with condition
Hopefully no one disagrees with this one, but we should very very very rarely be setting a variable with a condition action (the only time I could think of is if the condition was incredibly complex, but in that case there are bigger issues in the data format).

A simple if() expression as the input should be used instead. I would also add in if a variable should be used at all.

condition

Filter after get items
Another no brainer, get items has the filter query which should be used instead (unless its a on a non delegatable query like null results in SharePoint).

filter query

This one has some big negatives too, it's a massive waste of Power Platform API calls and can lead to incorrect data (if pagination isn't setup right).

Condition after trigger terminating flow
Just like 'Filter after get items' this is another no brainer, we should not be running the flow just to terminate it. The flow trigger condition will stop the flow from even running. This again saves Power Platform API calls and keeps your flow logs a lot tidier and easy to read.

condition trigger

Use of Compose
This is kind of my 'red flag to a bull' design in a flow (I've even done a whole blog on it, Using Compose the Right way). Composes are misused all of the time in Power Automate, there are a few niche cases where they are useful, and they can be good for debugging your code, like a console.log(). But they should not be in your production code, they waste API calls, clutter your variable list and just generally annoy me.

Rename without action name
Naming conventions are key to good code, and the same is with Power Automate. Having no naming convention could be a point on its own, but hopefully that's too obvious. But one mistake I see is when people have a naming convention, but they totally rename the action.

Why is this bad, well it makes reading the flow so much harder. Most actions have the icon based on the connection, so every SharePoint action looks the same.

action naming

This means I have to open the action to understand which action it is, this is a big pain when trying to debug or do a code review.

Advanced

Loop for one item
I see this a lot (and I almost put this in the basic group). Because Power Automate tries to help, everytime you put a key/field from an array into an action it drops that action into a loop.

Now I know Microsoft is just trying to help, and it is useful, but it also means that when we filter an array expecting just one result it gets put into a loop. This loop action is not only pointless and wasteful, it means sometimes a variable has to be used.

But there is a simple solution, the first() expression, or my prefered array position (where we add [0] to our array expression).

first from array

Multi variables instead of object
Often we don't even need a variable, but if we do for something like config, we should not be having multiple (say more than 3).
Instead we should be using one object variable, it means a little more coding the expression because we have to add the key to the variable.

multi var

Or you could just use a Parse JSON to make it easy.

You can even update them with the setProperty expression.

set property expression

Not using coalesce
Coalesce is our friend if we want our flow to be kept simple and efficient, so when its not used it means the flow hasn't been designed right. What do I mean, well coalesce allows you to pass in multiple inputs and it uses the one that is not null. So we should be using this in branching, we then use the coalesce to unify all the possible branches back into one.

coalesce

Advanced

Condition in loop
You should never need to put a condition as the first action in a loop. Especially if it only has an action in one branch (single branch condition).

It's very wasteful to pull all the items into the flow, then check each one. What we should be doing is using the action query filter, or a straight filter action if the filtering happens after the get items.

That is not so controversial, but what is is that I think you should have the same rule even if you have an action on both conditions. So I would filter by true, loop over those items. Then do a filter for false and loop over those separately. This may sound a little pedantic and pointless, but:

  • The flow runs a little quicker that way
  • Drives consistency with single branch conditions
  • Easier to read logs for debugging as each part of the process is separated.

condition filters

Think of it from a logical way, if you were sending out accepted and rejected letters, would you:

  • Go through the pile, and process each with accepted or rejected

Or

  • Sort into accepted and rejected piles, then process all the accepted, then all the rejected

Condition branching
This one is kind of similar to 'Condition in loop', we should not be using conditions as branching. Conditions should always merge back into one branch, there are a couple of benefits:

  • More efficient (no duplication of actions across branches)
  • Easier to maintain (update one action instead of 2)
  • Easier to read the flow
  • More stable in development (nesting can impact/slow down the browser and make development harder)

If you want to know more about this overarching approach check out my full blog on it Power Automate, The Direct Methodology


I'm sure there will be disagreements with my selection and ones I missed, so feel free to add to the comments.

Top comments (5)

Collapse
 
joelzehring profile image
joelzehring

Thanks for these illustrated suggestions! Now excuse me while I go and review my cloud flows...

Collapse
 
balagmadhu profile image
Bala Madhusoodhanan

Love the blog!!!... Simple tricks to make the maintenance much more easier... Low Code still need coding logic !!!!
think

Collapse
 
naufalwp profile image
Naufal Wahika Putra

Thank you so much for the post and series!
Learned a lot reading from you.. still have much to learn on how to effectively create Power Automate flows

Collapse
 
yd profile image
Info Comment hidden by post author - thread only accessible via permalink
Youcef Doumandji

Hi David,
Thank you for your article. Pity that the screen copies are not neat !

Some comments may only be visible to logged-in visitors. Sign in to view all comments. Some comments have been hidden by the post's author - find out more