What are Expressions?
Flow has a rich set of actions, based on connectors but many a times there is a need for operations like get current date, adding numbers, concatenate strings etc. That’s where expressions come to the rescue. Power Automate leverages the same Workflow Definition Language used by Azure Logic apps. For new users who are unfamiliar with the expression language, there is an inline help experience that shows how to use each expression as they build out their flow.
Expressions are a set of functions that can be used to perform specific actions within a flow.
Examples of actions: Manipulate strings, Working with dates, Converting data types, Perform logical functions, Perform mathematical calculations, Perform complex conditional statements, etc.
Sample expression :
replace (text, oldText, newText)
Sample data :
replace (‘The Old World’, ‘Old’ , ‘New’)
Output : The New World
Expressions can be used in flow actions, conditions and trigger.
Where can Expressions be used?
Actions
Expressions can be used in any flow action.
Conditions
Expressions can be used in any flow condition.
Trigger
Expressions can be used in flow trigger conditions.
Useful to conditionally trigger flows and thereby save flow runs.
Expression Editor
Classic Editor | Modern Editor |
Generally Available | Experimental Feature |
Less space to enter expression | Expression space is large |
Switch required to dynamic content | Dynamic content available within expression window |
Requires user to click button to confirm expression | Updates the expression on the fly |
Best Practices
- Power Automate reads and processes dates and times in Coordinated Universal Time (UTC).
- Rename actions with meaningful names (since these names would be used in expressions).
- Add expression as Notes to actions and conditions (makes it easy to read the underlying expression). •
- Use Peek Code to check for expression syntax (peek code is your friend).
- Use the ? for reading optional properties from JSON objects.
- [] Array notation in JSON objects.
- When updating expression, make sure to hit the Update button (classic editor).
Download Flow samples with expressions:
Reduce number of variables and Save API Calls – https://github.com/rdorrani/Microsoft-Flow/blob/master/Expressions401-ReducenumberofVariables-SaveAPICalls_20210211210303.zip
Error handling of flows with expressions – https://github.com/rdorrani/Microsoft-Flow/blob/master/Expressions401-ErrorHandling_20210211210406.zip
Calculate number of working days for 2 given dates – Microsoft-Flow/Expressions-CalculateWorkingDaysbasedonagivendaterange_20211018182851.zip at master · rdorrani/Microsoft-Flow (github.com)
Expression to grab the flow run link:
concat('https://us.flow.microsoft.com/manage/environments/', workflow()?['tags']?['environmentName'], '/flows/', workflow()?['name'], '/runs/', workflow()?['run']['name'] )
To learn about flow expressions check out the Expressions Video:
To learn about flow trigger conditions leveraging expressions and thereby saving API calls:
Keep flowing!
Regards,
Reza
Your style is unique in comparison to other people I have read stuff
from. Thank you for posting when you have the opportunity, Guess I will just book
mark this site.
Thank You. Appreciate the feedback.
Pretty darn awesome Reza. In particular the combination of solution 1 with 3 to get the complete error handling solution. If we’re getting picky though, do you need an initial compose in the catch scope before the filter array as it’s not called upon anywhere? I think this will become my default flow template. Thanks for the brilliant demo.
Thanks Damien. You do not need the initial compose. That was just to explain the concept.
I plan to build a video next on top 15 flow tips 🙂
Hi Reza, I appreciate your help to Power Platform community users with your great knowledge.
Please make a video on fetching InfoPath form file (.xml) in Power automate & read all columns (nodes/xpath) data in details including attachment, repeating table structure and map it to SharePoint list. It will great help in data migration projects from InfoPath to Power Apps.
Great idea but that will involve a lot of work and time. This would probably be something that ISV’s would be building and selling.