{"id":110845,"date":"2017-07-27T12:00:46","date_gmt":"2017-07-27T19:00:46","guid":{"rendered":"https:\/\/www.microsoft.com\/en-us\/power-platform\/blog\/power-automate\/use-expressions-in-actions\/"},"modified":"2017-07-27T12:00:46","modified_gmt":"2017-07-27T19:00:46","slug":"use-expressions-in-actions","status":"publish","type":"power-automate","link":"https:\/\/www.microsoft.com\/en-us\/power-platform\/blog\/power-automate\/use-expressions-in-actions\/","title":{"rendered":"Use expressions in flow actions"},"content":{"rendered":"
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\u2019s possible inline in any flow action. Microsoft Flow leverages the same Workflow Definition Language<\/a> 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\u00a0Add dynamic content<\/strong>\u00a0menu.<\/p>\n <\/p>\n You will see a new\u00a0Expression<\/strong>\u00a0tab, 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\u00a0See more<\/strong>\u00a0on each category.\u00a0<\/p>\n <\/p>\n 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\u00a0Dynamic content<\/strong>\u00a0tab 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 \u00a0select 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.<\/p>\n <\/p>\n 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<\/a>.<\/p>\n 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:<\/p>\n The 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 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.<\/p>\n 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 Working with dates<\/h2>\n
\n
utcnow()<\/code> into the Start Time<\/li>\n
adddays(utcnow(), 1)<\/code> into the End time<\/li>\n<\/ul>\n
utcnow()<\/code> expression gets the time that the flow runs at. Expressions like
adddays()<\/code> or
addhours()<\/code> can be used to add (or subtract) time – in this example, adding one day. You can also use the
formatDateTime()<\/code> to get portions of a date:
formatDateTime(utcnow(), 'MMMM')<\/code> will return the current month. You can see the various date formats here<\/a>.<\/p>\n
Manipulating strings<\/h2>\n
replace(triggerOutputs()['headers']['x-ms-file-name'],'\/','_')<\/code>. 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.<\/p>\n
last(split(triggerOutputs()['headers']['x-ms-file-name']),'.')<\/code>.<\/p>\n
Advanced content handling<\/h2>\n
xml()<\/code> expression to do that. Then, you can use the
xpath()<\/code> expression to extract a specific node from that XML.\u00a0<\/p>\n