My big 5 tips for Power Automate

I've done a lot of training and lot of coaching around Power Automate, and there are some key things which I always try to point out to people to ensure that their automations are easy to understand and maintain going forward.

1. Name your Actions

By default all actions placed into your automation get given a name, however if you start to run up multiple instances of the same action, then you end up with Action 2, Action 3 etc. This makes is difficult to maintain your automation for a number of reasons. Firstly, when you collapse all of your actions, it's not immediately clear what each action is doing, which when looking at the collapsed view you realistically want to follow your logic through.
Secondly, when you are trying to use dynamic content from those actions, later in your automation, again it makes it extremely difficult to ensure that you are selecting the dynamic content from the right action.

There is no universal naming convention, you will find what works for you, so consider the following when naming:

  • Make sure it reflects what the action is doing
  • Don't make it too long with too many spaces, particularly if you are going to be referencing it using an expression


2. Make comments

While you are creating your automation you will know the whole process inside and out, but consider whether you will still understand the process when your return in 6 months or even a years time. When we write code, we add comments, to act as reminders for us at a later date, and often to demonstrate thinking. This is particularly useful when we come up against an issue and we have to think of another way around.
Comments allow us to explain all of what I've just mentioned. They don't need to be long, but believe me it's worth it to avoid the "what was I thinking?" moment at a later date.

3. Don't loop unless you really need to

One of the things which really annoys me about Power Automate is when it puts loops in when I don't really want them. I know the platform is only trying to be helpful, and for a lot of people it will help them, but I'd rather it didn't.

Why don't I want the extraneous loops? Firstly the OCD in me really kicks in because it starts to make my automation look untidy. Also, whilst not always true, I've found that an action being inside a loop, even when only running once, executes slightly slower than if it's not.
It's common that I only actually return one result, so why would I want to loop if I know I only have one item. This is often seen when using "Get Items" or "Get Files" in SharePoint, as the action allows me to select an item based on a piece of metadata other than the ID. But the result which is returned is an array, which is designed to hold several items, so I either live with the loop or I do something about it.

For this I always tend to resort to expressions to reference my Get Items action, which starts to push users slightly out of the realm of automation basics, into intermediate territory. So rather than using a loop, I would use an expression which looks like the following to retrieve the Title:

body('Get_items')?['value'][0]?['Title']

Notice that after the ['value'], I have a [0] which means I'm going to take item number 1 in the array. This means that I can extract the Title dynamic content, without having to loop through a single item.

4. Don't tie business processes to your account

One of the biggest issues I see with automations is where users develop a process but then leave all of the connections pointing to them. All of a sudden, all items are being updated by the process creator, all emails are coming from them, and ultimately, when they leave then the automation begins failing because that user is no longer valid.

Before deploying to production, consider adding a connection using an unattended account, and account which is not used for anything else other than facilitating the automation.

5. IF you have lots of outcomes THEN Consider Switch

Finally, if you have a lot of different potential outcomes within your automation then think twice about reaching straight for the conditions. Let's say we are going to have different actions taking place on each day of the week, therefore we have seven potential outcomes to the question "What day is it?".

Most automators will reach for the condition action and so end up with a number of nested conditions working with only two results, is it true or is it false. Again my OCD will kick in here as it looks really untidy, it's difficult to immediately see what the potential routes through are, but ultimately there is a limit of 8 levels of nesting for the actions, so if seven of them are taken with the basic logic then it doesn't leave us much to play with.

In this scenario, consider using a switch statement, where you define a number of different legs without the nesting which means that it's much tidier, and much clearer when you are reading through your automation.

So they are some of the tips which I generally give out when talking about Power Automate. As always, I welcome any feedback that you may have.

Comments

  1. Matt - thanks very much for this - the Switch/Case example is pure gold!

    ReplyDelete

Post a Comment