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.
- Filter to get trigger condition
- Use full array then replace with filter
- Excel set then change to dynamic
- Modifying the JSON parse
- Array structure []
- Union for remove duplicates
- Object bar for multi variables
- Run URL
- Get who called flow button
- 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.
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.
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.
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.
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.
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.
(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.
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'])
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.
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.
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.
Top comments (3)
Thanks Dave - very useful - particularly 2, 4 and 6! Cheers mate
Hey David, developing on the third example in #4, crmtipoftheday.com/1437/duplicate-... shows how to change the element titles as well as descriptions
Thank you, some helpful tips. I've made note of all these. 🙂