Using dynamic content in Power Automate
As a Low/No Code platform, one of the main goals of Power Automate is to make things easier for the user, avoiding the need of coding to achieve its results. One of the features that provides this easy use is the “dynamic contents”, which are basically a quick and user-friendly way to access data from the trigger or previous actions in a flow.
All flows need to transfer data from one action to another, so this is that kind of feature that the Power Automate user will need to work with in a daily basis. In this blog post, we will explore how the dynamic contents work with in real-life business scenario and how to make it even more powerful by using the “Expressions” (check this article to learn how to use expressions in Power Automate).
Interacting with actions outputs in Power Automate
In a flow execution, triggers and actions generate valuable data that you might want to use later in your process. For instance, if your flow begins with a Microsoft Form submission, you may need to access the answers to each question for future steps.
To see the data from triggers and actions, head to the “My flows” page (highlighted in yellow) and select your desired flow, (for this post, ‘MS Flow — Medical Services’, which is highlighted in green):
On the Flow details page, you’ll find a list of all recent flow runs in the last 28 days, showing their dates, duration, and statuses. Clicking on a specific date/time (highlighted in yellow) will take you to the ‘Flow run’ page with detailed information.
In the flow run page, the trigger (highlighted in yellow) and the actions (highlighted in bule) are presented. The trigger will always be on the top of the process structure, as this is the event which starts the flow:
In this scenario, our flow captures a form response, examines the answers, and inserts a row in an Excel Table based on that data. When you click on any action box, more details about its inputs and outputs will appear. For our case, the outputs from “Get response details” action represent each question’s answer in the Form response (highlighted in green). If you need to work with raw outputs, you can access them by clicking the button highlighted in blue (if you don’t know how to work with raw outputs, check this article).
While the output fields above are presented in a user-friendly format (matching to the respective question in the MS Form), their logical reference may not always be so clear. To understand the logical reference, you can refer to the raw outputs pane, where each property (highlighted in yellow) is an id corresponding to the same properties from the previous image (the MS Form questions).
To manipulate any of its output values, we can either use dynamic contents or expressions. The dynamic contents are usually easier to read by a human, as they use the alias, while the expressions use the logical reference.
What is Dynamic Content in Power Automate?
Dynamic content provides an effortless way to access the outputs of actions or triggers. It offers a user-friendly interface, using “display names” (or aliases) to identify each property instead of complex logical references.
For instance, it would be much simpler to refer the Form responder’s email by the label ”Email address“ rather than the question’s unique id (which is “r8294b1a631834c889ca0e8cc41fcdec4”). This feature makes Power Automate an excellent tool for non-professional programmers, enabling users to create powerful solutions quickly and easily. Embracing dynamic content streamlines the flow-building process and enhances overall usability.
How to use Dynamic content in Power Automate?
To access the dynamic content list, simply click on the input field of any action (highlighted in yellow). A new pop-up will appear, displaying available content from previous actions. Note that future actions (marked in red) cannot be accessed in this list, as the flow follows a linear process. The list includes the related action/trigger (highlighted in pink), the display name (alias) of the property linked to the dynamic content (highlighted in green), and a brief description (highlighted in blue) about each dynamic content item:
By just clicking in the dynamic content, it will automatically populate the input field:
When using the ‘Add row into a table’ action, which comes after ‘Get response details’ and ‘List rows in a table’, the dynamic content list changes. Now, it will include additional dynamic contents, categorized by the action that generated them. The ‘ List rows present in a table’ action (highlighted in blue) generates dynamic contents highlighted in green, while the ‘Get response details’ action (highlighted in yellow) generates dynamic content highlighted in pink. This distinction simplifies the process of selecting the appropriate dynamic content for your flow:
If we roll scroll down in the dynamic content pop up, we will see much more content options from the ‘Get response details’ action, matching not only to the MS Form questions’ answers, but also including some metadata (like the responder’s email address and the date/time of the submission):
In the example below, you can see how the dynamic content from the MS Form response populates an entire Excel table (in this article, you can find more on how to integrate Excel tables with Power Automate, and in this one you can learn how to write and update data into tables with Power Automate). Thanks to the automated trigger, each Form submission triggers the tasks, capturing the relevant answers to fill the Excel table accordingly. This streamlined process ensures that data is efficiently collected and organized in real-time, making the workflow seamless and generating a “non-click solution”.
After populate the ‘Add row into a table’ action with dynamic content and running the flow by making a new form submission, this is the result:
How to use Expressions in Power Automate?
As mentioned earlier, while dynamic content provides an easy way to access data using aliases, expressions offer an alternative method to access properties by its logical references. But why would someone choose expressions over dynamic content in Power Automate?
Expressions come in handy when data requires transformations before use in another action. In the previous section, we included values from the MS Form response in the Excel table without any modifications, resulting in an odd format for the “Use medical services for” column, as the values were inserted as arrays (to learn more about data types in Power Automate, refer to this article). To extract only the answer values without quotes and brackets, an expression can be used, like an Excel Formula, ensuring a cleaner and more structured data output.
To get started with expressions in Power Automate, simply click on the input field you wish to work with (highlighted in pink). This will open the dynamic content pop-up. Next, switch to the ‘Expression’ tab (highlighted in yellow) and type your expressions in the ‘Fx’ input (highlighted in green). While there’s a list of some possible expressions available (highlighted in blue), referring to the official documentation will provide a complete set of expressions:
After entering an expression, a tooltip will appear, providing instructions for that specific expression’s usage. For instance, using the ‘replace()’ expression (highlighted in yellow) shows the expected values within it (highlighted in green), along with brief descriptions of each (highlighted in blue), and the expression’s output (highlighted in pink):
In summary, the ‘replace()’ expression searches for specific text within a string and replaces it with another text. In our case, we use it to find quotes within the ‘What do you use internet medical services for?’ field and replace them with empty strings, removing the quotes. The syntax of the expression is simple: replace([main_text], [old_text], [new_text])
To add the answer to ‘What do you use internet medical services for?’ as a ‘main_text’ withing the expression, you have two options: identify it by the logical name of the property or dynamically insert it, which is much simpler. To do the latter, place your cursor inside the expression’s parenthesis, switch to the dynamic content tab (highlighted in yellow), and select the desired property (highlighted in blue). Once clicked, the dynamic content expression will be automatically generated (highlighted in green):
To pass the other required parameters for the ‘replace()’ expression, use single quotes to encapsulate both the text to be replaced (double quotes) and the text that will replace it (empty text). For the text to be replaced, insert a double quote between single quotes (highlighted in green), and for the new text, use only two single quotes (highlighted in blue). Since both values are strings, they need to be surrounded by single quotes, even if they consist of actual quotes or an empty text. Remember to separate the parameters by commas and place them inside the parenthesis (highlighted in yellow):
The whole expression looks like this, where:
- The expression is highlighted in pink;
- The parenthesis, that must surround all the expression parameters, are highlighted in red;
- The first parameter (the main text, which is the Form answer) is highlighted in yellow. Although we added this value through dynamic content, it is represented by its logical reference in the expression;
- The commas, that must separate each parameter, are highlighted in dark blue;
- The second parameter (the old text, that will be replaced), is highlighted in green;
- The third parameter (the new text, that will replace the old one), is highlighted in light blue.
After running the flow again, this is the result: no quotes in the data inserted into the table (highlighted in yellow):
Next, we’ll remove the brackets. The process remains similar, but this time we’ll use the first replace expression as the “main_text” parameter. Yes, expressions can be nested within other expressions, which is quite common in most cases.
Now the expression will looks like this, and it will replace only the ‘[‘ bracket:
- The expression is highlighted in pink;
- The parenthesis, that must surround all the expression parameters, are highlighted in red;
- The first parameter (the whole expression used before, that removed the quotes) is highlighted in yellow;
- The commas, that must separate each parameter, are highlighted in dark blue;
- The second parameter (the old text, that will be replaced), is highlighted in green;
- The third parameter (the new text, that will replace the old one), is highlighted in light blue.
Then we repeat the same process one more time, to replace the ‘]’ for an empty string. After running the flow, this is the result (highlighted in blue):
This is already an improvement from using the original answer text. However, we can add one final step to include a blank space between the comma and “Medical.” To achieve this, even that we don’t need to replace any text; instead, we may use the ‘replace()’ function to replace the text ‘,’ with ‘, ‘, effectively adding the desired blank space after the comma:
replace(replace(replace(replace(outputs(‘Get_response_details’)?[‘body/r421f6f7cb5894c18858de52bb9bf04df’], ‘“‘, “), ‘[‘, “), ‘]’, “), ‘,’, ‘, ‘)
This is a complex expression to read, but once you split it in several steps, it becomes easier. You can also learn more on how to clean and extract texts with Power Automate in this article. After running the flow one last time, this is the result: a much better text than the original one.
Conclusion
Dynamic contents are one the most powerful features from Power Automate. It makes the tool use easier, allowing that people without a strong IT background to build flows and streamline processes.
Although the dynamic contents can solve a large share of a business daily problems, sometimes we need to goo a little further to achieve better results, and that is when we may use the expressions. Power Automate provides a similar experience to the Excel formulas, keeping a similar syntax for the expressions and allowing the use of dynamic content inside it.
Originally published at http://digitalmill.net.