Create a Word Document Based on a Template

It’s fairly common for many business processes to somehow require the production of a document in their workflow. An easy example of that is of a salesperson needing to send out a well-formed quote to a potential client. Another would be when the process calls for some form of review and doing so means going over a document rather than viewing them directly from Dynamics 365 (perhaps buying a license for the whole business is proving a little costly). Sending an email to external or internal clients alike with a document attached is also not unusual.

If the document required is in Word format and considering that the data resides in Dataverse, there are three options available that I am aware of: (1) using the out-of-the-box word templates functionality, (2) setting up a report using SSRS, and (3) using Power Automate and its readily-available connectors. For this post, let’s take a look at the third option.

1. Build the template

Plain text controls, which will hold the data pulled from Dataverse, must be inserted into the template. If the data is repeating, such as when trying to get data from a related table (meaning the N side of a 1:N relationship), a repeating content control must be added. Once this template is built, store the document into your Document Library of choice in Sharepoint.

2. Build the flow

2.1 Configure the trigger. In this example, the flow kicks off when a record is modified.

2.2 Retrieve the records the data from which are pulled into the word document. Note that even when only one record is expected, use the List records action regardless. The reason for that is in Step 2.4, the Select data operation requires an array as the argument in its input parameter.

2.3 Using the Get file content action, get the content of the template stored in a Document Library.

2.4 The Select data operation allows shaping the content of the objects within the array (Reference: In this case, I only want to pull data from three fields, namely: first name, last name, and email address. The data for these three are to be taken from the List records action. It’s also important to note that field names on the mapping table below should match the tag of the corresponding control added into the template.

2.5 The Populate a Microsoft Word template provides the capability to enter the retrieved data onto the word template. The controls on the template were automatically detected when adding this action. However, I want to switch the input box into an array by clicking the tiny icon on the top-right corner. Doing so will compress the input into a single box. This is where the output from Step 2.4 will go.

2.6 Create the file using the action Create file. Name it however you want, and you’re done!

That’s it. Thanks. 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: