{Solved} How to populate word template with Dynamic files in Power Automate

Hello everyone and welcome to my blog. In today’s blog I will show how you can Populate a word template in Power Automate with Dynamic files.

Below is a word template that I will use for this demo.

It has three text template placeholders and I have put appropriate tag and name for each of this.

I uploaded this template in OneDrive. The requirement is to read the template from OneDrive, fill the word template and then save the filled document back to OneDrive. All using Power Automate flow.

Power Automate has the Word Online (Business) connector that has an inbuilt function to populate a word template.

When you select a pre-defined word template in this action, the action is smart enough to identify the template placeholders and show it as parameters which you can set.

But not always you can select a pre-defined template like this. Sometimes your requirement would to take the File as a dynamic value. In the below example I have set the File property of the action a dynamic value. The value is basically an input to the workflow.

When you provide a dynamic input to File, the action need a JSON for dynamicFileSchema. Let’s understand what should be the JSON for this field.

To understand this, let’s do a deep dive here.

You might already be knowing this. .docx files are essentially .zip files comprising of multiple documents. To understand how templates are stored inside a word document, I changed the extension of my template from .docx to .zip. And then extracted it.

In the extracted folder, you will find a folder “Word” and within that a file document.xml

Open the document.xml file in an editor of your choice and search for the template placeholders by name. In the below example, I am searching for the firstname template placeholder.

Notice the w:id tag highlighted in green. The w:id value is the one we need to set.

Please not that you need to use the exact value that’s there in the w:id. For the email placeholder, the w:id tag has the a ‘-‘ with the number value. Make sure to use the whole value including the ‘-‘.

Once you have found the w:id value for all the template placeholders, it’s time to construct the JSON for dynamicFileSchema property.

Below is JSON.

{
  "826248736": "Dutta",
  "1475492909": "Debajit",
  "-1678028797": "debajit.dutta@xrmforyou.com"
}

And now when you will run the flow, you will find the template placeholders are replaced with the provided values.

Hope you liked this post. If this post has helped, you can buy me a coffee. Links on right pane.

For similar topics on Microsoft.NET and Power Platform, subscribe to my blog using the Subscribe option on right pane.

You will also like the below posts.

Debajit Dutta
Business Solutions MVP


Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe to get the latest posts sent to your email.

Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading