Automating the generation of Word documents through the use of Word Document Templates in Model Driven Power Apps is a common task that has been possible to do for some time now using the Populate a Microsoft Word template action from the Word Online (Business) connector in Power Automate. There are countless posts out there that explain how this is done.
However, this is a bit of a tedious process as it requires manually specifying in the flow step the value for each content placeholder in the document template. It also involves having to store the Word Document Template in a location where it can be retrieved by the flow to be able to use it, for example OneDrive or SharePoint.
In the rest of this post I describe what I believe is a more streamlined way to go about automating the generation of Word documents. Not too long ago I found that there is an endpoint that can be used to generate Word documents from Word Document Templates. The endpoint is composed of the environment URL followed by /_grid/print/print_data.aspx. This allows the generation of Word documents without having to deal with the nuances that I mention above. In other words, the document template only needs to be present in the Dataverse environment and all data is automatically populated in the Word document with no need to specify what data goes in what content placeholder within the document template.
With this in mind, I created a Power Automate flow that uses the Invoke an HTTP request action from the HTTP with Azure AD connector in Power Automate to make a call to this endpoint to generate the Word document based on a given Word Document template. Then I used the return value which is the content of the word document to create the Word file in OneDrive. Here’s what the flow looks like with the details to follow:

Flow Steps
Step 1 is the trigger of the flow which in this case is when a record is added, modified or deleted.
Step 2 saves the environment URL into a variable that’s manually populated for later use. It would be your environment base URL, for example: https://orge092ce7b.crm3.dynamics.com. Normally you would have an automated way to obtain the environment URL for ALM purposes, but this will do for this post.
Step 3 uses the aforementioned Invoke an HTTP request action to first obtain the object type code of the table for which the document is being generated. This is needed later when calling the endpoint.
Step 4 retrieves the Document Template to be used to generate the word document based on the name of the template
Step 5 once again uses the Invoke an HTTP request action, but this time it is to generate the Word document content using our featured endpoint. The following needs to be provided for this call:
Accept Header:
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Language Header:
en-US,en;q=0.8
Content-Type Header:
aplication/x-www-form-urlencoded
Body of the request:
- exportType: MergeWordTemplate
- selectedRecords: This needs to be the encoded set of row IDs for which the document will be generated. In our case, it’s just the one record. However it still needs to be provided as an encoded array of GUIDs. In javascript you would obtain it like this:
encodeURIComponent(JSON.stringify(['id here'])). In Power Automate however, there’s nothing like JSON.stringify. You get around that by providing your row ID flanked by the following set of characters: %5B%22 and %22%5D where %5B is the encoded string for an opening square bracket, %5D is the encoded string for a closing square bracket and %22 is the encoded string for quotes. - associatedentitytypecode: This is where the entity type code that we got on step 3 needs to be provided
- TemplateId: This is the GUID of the document template we got in step 4
- TemplateType: 9940 (9940 is global and 9941 is personal)
Putting it all together, the body of the request would be as follows. The pieces in bold would be the dynamic values obtained from the previous steps.
exportType=MergeWordTemplate&selectedRecords=%5B%22@{triggerOutputs()?['body/contactid']}%22%5D&associatedentitytypecode=@{outputs('Invoke_an_HTTP_request_to_get_Object_Type_Code_of_Contact_Table')?['body']?['value']}&TemplateId=@{first(outputs('List_rows_for_the_Document_Template_Table')?['body/value'])?['documenttemplateid']}&TemplateType=9940
Finally, step 6 uses the output of step 5 as the File content to generate the Word document in One Drive.
I hope you find this tip useful.