Become a Dynamics 365 expert with Syvantis Learn
Provide additional details about the offer you're running.
This store requires javascript to be enabled for some features to work correctly.
Provide additional details about the offer you're running.
Generate Word documents from templates in Power Automate
Power Automate • Power Platform
Learn how to use Word templates with Power Automate to automatically create polished documents from business data and email them to customers. This Fast Class walks through an example using Dynamics 365 CRM case data, Word content controls, Power Automate arrays and variables, SharePoint, and Outlook to generate and send a formatted customer case report.
Power Automate can automatically populate Word templates with data from connected systems, giving you a way to create consistent, professionally formatted documents without entering information manually. In this example, we'll create a customer case report using data from Dynamics 365 CRM. The report separates open and resolved cases, adds information from the customer's account record, and is automatically emailed to the customer's primary contact. Although this example uses Dynamics 365 CRM, you can use other data sources that Power Automate can connect to.
What you'll need
For this example, you'll need access to Power Automate and the Microsoft services used by the flow, including:
The Power Automate license may be assigned directly or included with another applicable Microsoft license.
Planning the customer case report
The report in this example uses case and account information from Dynamics 365 CRM. Open cases include:
Resolved cases contain similar information, but use the date the case was resolved instead of its creation date. The report also uses the account name for its title and an image from the account record for branding. Power Automate is particularly useful here because it allows you to filter and separate the records into open and resolved cases. The process could also be automated to generate and email the report on a recurring schedule.
Creating the Word template
The Word template uses content controls to identify where Power Automate should insert data. Content controls are added from the Developer tab in desktop Word. The Developer tab is not displayed by default, so you may need to enable it in Word's settings. The types of content controls demonstrated include:
The example report uses plain text, image, and repeating section controls. Plain text controls hold values such as the account name and prepared date. An image control provides the account's branding. Repeating section controls make it possible to dynamically add rows to the open and resolved case tables.
Setting up repeating table rows
A repeating section control is added to each table row that needs to repeat for multiple records. Plain text controls are then placed inside the individual cells. Each text control within the repeating row needs a unique name. These names become important when building the Power Automate flow because they are used as keys when mapping case data into the Word template.
Building the Power Automate flow
The example flow is manually triggered using the account ID, or GUID, as an input. The trigger could also be replaced with an automated or recurring trigger if the report needs to be generated on a schedule. Several variables are initialized to organize the data:
After initializing the variables, the flow retrieves the account record using the ID provided by the trigger. The account information is later used to populate the account name and image within the report.
Retrieving open cases
The flow uses a List rows action to retrieve open cases associated with the account. An OData query filters the records to return cases belonging to the appropriate account with a status code of 1, representing open cases. A FetchXML query could also be used instead. An Apply to each action then loops through the records. For each case, the flow creates an object containing the information needed by the Word template. The keys in this object match the unique names assigned to the content controls in the template. Power Automate's formatDateTime function is also used to format the case's created date before it is inserted into the report. Each completed object is appended to the open case array. When the loop finishes, the array contains the information needed to populate all of the report's open case rows.
Retrieving resolved cases
The process is repeated for resolved cases. Another List rows action retrieves the appropriate case records, this time using a status code of 5 for resolved cases. The flow loops through these records, creates the required case objects, and appends them to the resolved case array. At the end of this process, the flow has separate arrays for the open and resolved sections of the report.
Populating the Word template
Next, the flow uses the Populate a Microsoft Word template action. The template is stored in SharePoint, although OneDrive can also be used. You select the appropriate location, document library, and path to the template. The flow then maps data to the template's content controls. For the plain text fields:
For the image control, the flow passes the image object containing the image file type and contents retrieved from the account record. Finally, the open and resolved case arrays populate the template's repeating sections, creating a row for each applicable case.
Emailing the completed document
Once the Word template has been populated, the flow retrieves the account's primary contact so it can access the recipient's email address and first name. An Outlook action creates the email and uses the contact's information to personalize the message. The completed Word document is then added as an attachment using the output from the Populate a Microsoft Word template action. Be sure to include the .docx extension in the attachment's filename. Without the correct extension, the recipient may receive the attachment as an unknown file type.
Running the flow
To run the example manually, retrieve the account ID from the Dynamics 365 CRM account record and provide it as the input when launching the flow. Once the flow completes successfully, the customer receives an email containing the generated Word report. The completed document contains:
The result is a formatted customer report generated automatically using data from CRM.
Why automate Word documents with Power Automate?
Using Word templates with Power Automate allows you to combine structured business data with consistent document formatting. While this example focuses on a customer case report, the same approach can be adapted to other scenarios where a team needs to automatically create and distribute documents. With this process, you can:
* This transcript summary has been generated from the Fast Class video by Microsoft Copilot. The Fast Class itself was prepared and taught by Syvantis expert consultants.
TUNE INTO THE LIVE CLASS
Ask your questions and get real-time responses from your trusted Syvantis consultants.
What's on the schedule?
Dynamics 365 Business Central
Dynamics 365 Sales (CRM)
Dynamics 365 Customer Insights
Power Platform
Keep learning...
Business Process Designers. Technical Experts. Dedicated Partners.