Microsoft’s recommended approach for creating documents in Power Platform is to use Power Automate and there is an out-of-the-box action called Populate a Microsoft Word template from Microsoft Word that can create a word document. The process is easy enough. You just need to enable the Developer tab in your Word and from that tab you add Plain Text Content Controls where you need to insert a text and Repeating Section Content Controls where you need to repeat a number of fields multiple times. Imagine order lines in an invoice.
After you’re done with the template, you would store it in a SharePoint or OneDrive location. In your flow you’ll add the Populate a Microsoft Word template action and point to the location of your word document. The action will detect and visualize all the content controls within the template and you can fill them in your flow using dynamic values just like any other fields. The most useful feature however is the repeating sections. They allow you to use any array of objects. As long as there are properties in your objects that match the name of the fields in the repeating section, they will be inserted in the document.
No repeating section in a repeating section
Often times you would need a repeating section in a repeating section. Imagine if you need to produce a list of accounts and their contacts. In your word document you can easily add repeating section to other repeating sections (e.g. hierarchical bullet points) but the Power Automate action does not support them. The only workaround is to use a simple Plain Text Content Control to your repeating section and enable Allow carriage returns (multiple paragraphs) and insert multiple lines of texts in it.
The extra touch
In you need to simulate the look and feel of bullet points, you would need to prepend a bullet point and a tab character to every line. You might already know that a tab is ‘\t’, but if you prepend the tab character using an expression like
concat('\t', 'mytext') it won’t work, because Power Platform will escape the backslash character with another backslash to make sure it is taken literally. So you will a different expression to make it work.
- To add bullet points to each line use either of the following expressions:
concat(decodeUriComponent('%E2%80%A2%09'), 'you line of text')
concat(decodeUriComponent('•%09'), 'you line of text')
- To add line breaks use the following expression:
In the above expressions I have used
decodeUriComponent and URL-encoded equivalent of “\t” and “\n” to insert tab and new-line characters. If you need to use any other special character in Power Automate, you can use the same technique.
If you need to know the URL-encoded value of any given character just open the Developer toolbox of your browser (Ctrl+Shift+I or F12 in Windows and Command+Shift+I in Mac) and in the Console tab, type
encodeUriComponent('\r') give it whatever combination of character that you need.
Leave a Reply