Although Microsoft Power Automate is powerful, we look at overcoming three common issues with creating HTML tables.
What is the ‘Create HTML Table’ action?
This Power Automate action allows you to take output from a previous step and format it in a cleaner, tabular format to then be used in perhaps an email or Dynamics 365 record. It allows you provide custom table headers and enables you to quickly lay out your data. However, there are times when you need to go beyond its standard functionality and produce something a little more complex; this is where problems can potentially creep in.
Problem 1: Custom table headers don’t allow for spaces
Update
Since this blog post was published, an even simpler method has been discovered. Simply type the required header label text into another program such as notepad and then copy and paste the whole string across into the Header and the space will be retained.As you can see from the above image, it is not possible to enter a space in your custom table headers. To solve this, we need to add a new step in between the existing steps called Select (part of the Data Operations category):
In the above image, you can see the new Select action and we have taken the output from our List rows step and used it to map fields to new key/value pairs, allowing us to use spaces in the labels. We then modify the Create HTML table action to use the output from the Select step and switch the Columns setting back to automatic. Our HTML table now has table headings with spaces.
Problem 2: Custom HTML links do not display correctly
There are times when listing data when you want to provide a link back to an individual record so that a user can go straight from an email to the data. However, as these links can be rather lengthy, you may want to try creating a custom link as below:
However, when the email is received, you will find this does not display correctly:
This is due to Power Automate sanitising the output of the step to prevent the HTML causing problems. Should you want to work around this, you can add an additional Compose action (also part of the Data Operations category) to take the output of your table action and correct the HTML:
The expression looks complicated but you can simply copy and paste the below and change the ‘Create_HTML_table’ part to the name of your table action if you have called it something else:
replace(replace(replace(body('Create_HTML_table'), '<', '<'), '>', '>'),'"','"')
When you then use the output from this Compose step in your email, you should get a much better result:
Problem 3: Table formatting is basic
As you can see from the previous problem, tables created by the Create HTML Table action look rather basic. With the addition of an extra Compose action, you can add a little formatting:
As you can see from the expression:
replace(replace(body('Create_HTML_table'),'<table>','<table border="1"'),'<td>','<td style="padding:20px;">')
by swapping out parts of the HTML, we can add a border around the table and some cell padding. This could be further expanded to add further styling as required. The end result looks far neater:
Summary
We hope these tips prove useful to those building their own Flows within Power Automate. If you are an existing Strategy 365 client and wish to discuss any of the points raised in this blog post, feel free to get in touch with one of our experts.