Power Automate 10 Quick Developer Tips
Tags: powerautomate, powerplatform, rpa, tips
Published: 2023-04-24 08:40:59

Developing in Power Automate can often be thought of as simple (its NoCode after all). But like all great software tools there are many shortcuts and top tips you pick up on your way. So I thought I would share the quick top 10 I have learned.

1. Filter to get trigger condition
2. Use full array then replace with filter
3. Excel set then change to dynamic
4. Modifying the JSON parse
5. Array structure []
6. Union for remove duplicates
7. Object bar for multi variables
8. Run URL
9. Get who called flow button
10. Peak code to see dynamic content (trigger bug)

## 1. Filter to get trigger condition
Using the trigger conditions is incredibly powerful, particularly for SharePoint/Dataverse lists, as we can have multiple flows triggered from one list.
But there is no easy way to create the trigger conditions, or is there. Fortunately the filter action is identical to the trigger condition, so as long as you set it to the trigger output, you can build your conditions there, then copy and paste it into your trigger condition.

![Trigger Conditions](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/py9509tjxficw91dkxs7.png)

## 2. Use full array then replace with filter
When used sometimes the filter doesn't have a schema shown, so you can't easily select the output fields. To get around this simply use the full, unfiltered array, in the ForAll. Then all the fields are available to select. When finished replace the array with the filtered array.

![Filter array](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9tjrht26lnnmlxbnuec8.png)

## 3. Excel set then change to dynamic
Again, another bait and switch kind of move, very similar to the filter. When using dynamic values in Excel (or SharePoint lists) you lose the fields as there is no schema (obvious as the dynamic value is empty until ran). To fix this first select a copy of the dynamic file, the fields will show for you to use. Then change back to a dynamic value when finished.

![Dynamic Excel fields](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l64pcq32cvat9knnrsnq.png)

## 4. Modifying the JSON parse
The JSON parse is particular cool because it can generate a schema from a sample. But there are a couple of issues you may see.
First it's a small sample set so might not be accurate, a good example would be when a value returned could also be undefined. To fix it simply edit the schema and remove the type.
Next is conditional, as the schema will default to all fields/keys being required, just remove any from the bottom that are not always found.
![Parse JSON](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q72p5icj1nxtlrqfdiqs.png)

Last is how difficult it is to find the right field when there are duplicate names in nested nodes. A cool tip is to add a description to the schema.
![Pares JSON descritpion](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p1b7cnk6wtq6r8baaxqo.png)

## 5. Array structure []
An old but classic, out of the box there is no index expression to get the nth item in an array. But there is a way, and that's the array position. Just edit the array expression and add a [#] after the item (after the body/value before 
the '?'). Whatever number is in the [] is the item in the array. While you are editing the expression you can use '?' to add sub fields/keys.

![Array position](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c4rn96pe5v0wcw5e7z5z.png)
_(above example is the first Created By Email address)_


## 6. Union for remove duplicates
Quick one, there is not distinct expression to remove duplicates, but actually there is. If you union an array with itself you remove all duplicates:

```
union(output('Get_Items')['body/value'],output('Get_Items')['body/value'])
```

## 7. Object bar for multi variables
Have lots of constant variables that you need in your flow but hate having loads of initialize variables, then why not declare just one. Using the object variable, you can create one variable for them all. 

![Object variable](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/szmxa764q02b2kmefbpt.png)


You can even save it to a file and use the get content if you want to make them configurable.

## 8. Run URL
We all hope out flows will never fail, but when they do a quick way to find the reason is a must. This simple expression added to any fail notification will take you directly to the failed run (no searching).

```
concat('https://make.powerautomate.com/manage/environments/', workflow()?['tags']?['environmentName'], '/flows/', workflow()?['name'], '/runs/', workflow()?['run']['name'])
```

## 9. Get who called flow button
Very much a niche, but did you know there are additional meta data passed to the flow trigger. An example is who triggered a button press. If you try and read it you get what looks like gibberish, but it actually base 64. A quick conversion and you have it.

```
decodeBase64(triggerOutputs()['headers']['x-ms-user-name-encoded'])
```

![Flow Caller](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y90bkbslg8dh4enjik9s.png)


## 10. Peak code to see dynamic content
The peek code is such a powerful tool that really should be used more. Its top use is dynamic inputs, as often Power Automate will be incredibly nice and mask the input with a more readable value. An example is a SharePoint list, the input dropdown calls an api to show you all the display names, you select one but the list id is stored in the input. So if you tried to add the list display name as a dynamic value it will fail. Peaking the code after select shows you exactly what is in the input.

![Peak Code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v4i0a1up0a3flikrx2wd.png)

My top discovery from this was the Outlook trigger folder, it defaults to the word 'Inbox', but select any folder (including Inbox) changes the input to the folder id (but still shows the display name). This causes so much pain when changing flow owner, as it's looking for the folder id not name.

![Outlook Trigger bug](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/arjcaz6n1mjgmwfsfdbp.png)

---

Hopefully at least one or two were new to you, and even though all are small, I think the whole is greater than sum of its parts.