Use expressions in flow actions
Flow has a rich set of actions, but sometimes users just need to do basic operations like getting the current time, adding numbers together, or replacing a part of a string of text. Starting today, that’s possible inline in any flow action. Microsoft Flow 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. To use an expression in your flow, first open the Add dynamic content menu.
You will see a new Expression tab, select that. On the Expression tab there is a list of the common expressions that are used inside of flows. They are categorized by area, and you can see the full list by selecting See more on each category.
When you select an expression, it will be added into the text box. You will need to fill in the parameters for each expression that you use. To include dynamic content from another action, select the Dynamic content tab and simply click the field you want to use -- it will add it to the expression instead of directly onto the action. Once you've completed your expression select OK and the expression will be added to the action. You can now click on the expressions inside of the action card and they will open up again for further editing.
Below are a few different scenarios for expressions. You can use the full list of functions available in the Azure Logic apps Workflow Definition Language, documented here.
Working with dates
One of the simplest examples for expressions is to manipulate dates. For example, using the new Get Calendar View action to get your events for the next day:
utcnow()into the Start Time
adddays(utcnow(), 1)into the End time
utcnow() expression gets the time that the flow runs at. Expressions like
addhours() can be used to add (or subtract) time - in this example, adding one day. You can also use the
formatDateTime() to get portions of a date:
formatDateTime(utcnow(), 'MMMM') will return the current month. You can see the various date formats here.
Sometimes, you need to replace a certain character in a string. For example, you want to convert '/' characters to '_'. That can easily be accomplished using
replace(triggerOutputs()['headers']['x-ms-file-name'],'/','_'). Replace takes three parameters: the string that you want to replace something in, the character you are replacing, and the character you want to replace it with.
A more involved scenario could be getting the extension from a file name. This requires splitting the filename on the "." character and then taking the last segment. That would look like this:
In this example, the split function would return a list of each of the segments separated by the period. Then, the last function returns the final item in that list, which would be the file extension itself.
Advanced content handling
One of the most advanced scenarios you can now use expressions for is Parsing XML messages. First, you'll need to convert your content, be it from a file or some other API to be an XML inside of the flow engine. Use the
xml() expression to do that. Then, you can use the
xpath() expression to extract a specific node from that XML.
Read more about this and all of the other supported expressions here.