I love Word Templates. Not sure if that’s ever been apparent with all my posts on Word Templates or my presentations on them, but I do. I think they are a great, yet sometimes, underappreciated part of D365/CDS. They do have some drawbacks like inability to sort results, only being able to get results from entities directly related to the entity you are running it from etc.
However, there is a Word Template Connector for Power Automate and as Power Automate can get data from anywhere in D365/CDS and other data sources, it removes a lot of the drawbacks from the inbuilt functionality. This is not something I’ve looked at before but after a recent talk from Claire Carmichael, I decided it was a good time to look at this functionality.
The way the connector works is that you create the Word Template, creating tags or placeholders for the data you are then going to populate via a Flow. You store the template in OneDrive for Business or SharePoint, point the flow at it, the connector finds the placeholders, you populate them with data and then create the file and store it somewhere. Let’s go through this step by step.
Firstly, open Microsoft Word add make sure you have the developer tab enabled. If you don’t have this enabled, you can find the instructions in this post.
Next build and design your template, create your headings, create tables etc. When you want to add in some content to be populated by a Flow, click on the developer tab and then choose the “Plain Text Content Control” and you will get a control that looks like this.
You can put whatever you want inside the box, this will be overwritten but it will appear as the hint text in the Flow, so adding additional detail in here will be useful. Next click on the field and then click properties. You will get the properties window pop up.
In here you specify a Title and the Title will determine the name of the field you see in your Flow.
Save your Word Template and then upload it to the Document Library of your choice, either OneDrive or SharePoint. Now it time to build your Flow. You can trigger the Flow however you like, but it’s the Word Online Actions which work their magic with this solution.
Search Word Online and find this Connector.
Then choose the “Populate a Microsoft Word template” action.
You will be asked to choose the Location, which is either OneDrive or SharePoint, then Document Library, which is either OneDrive or a specific document library in your SharePoint site if you have multiple, and the specific file which is your template you have uploaded.
When you choose the file, the action will update and it will give you boxes for the dynamic content to be put into. As you can see in the above screenshot, the name of the field is Title and the hint text is what is in the box from the content control. You can put dynamic content or hardcode something into this field.
Once you have populated the field, you then need to create the document. The action itself just takes the template and populates it, but doesn’t overwrite anything, so unless you create the file, you can’t use it.
The OneDrive for Business or SharePoint Connectors have actions that allow you to create a file. You choose the locations, populate the necessary fields and in the file content field, choose the file content from the Word Action.
From here you can grab the file, save it to other locations, attach to email etc. Stay tuned for the next part where we look at tables and repeating rows.
Caio for now!