Auto-Populating Word Templates with Power Automate

Imagine this: your process template documents automatically populated with the right data at the end of a process. Countless use cases exist, from contracts and invoices to reports and certificates. Power Automate is the perfect tool for this job, offering various triggers like scheduling, automation, events, or state changes.

In this article, we'll build a Power Automate flow to populate a Word document using Power Apps as the trigger. Here's what we'll need:

  1. A Word document template with Content Controls

  2. An online folder to store the Word template

  3. A Dataverse table (or SharePoint list) to store population data

  4. A Power Apps front end to trigger the flow (optional, but used in this demo)

Let's dive in!

Creating the Word Template

First, we need a Word template with Content Controls:

  • Open a blank Word document and enable the Developer tab.

  • If not enabled, go to File > Options > Customize Ribbon.

  • Add Content Controls to capture the necessary information.

  • For this example, we'll add six controls for contract details and assign titles and tags

  • Save the document to a SharePoint Document Library or OneDrive.

Setting Up the Data Source

Create a Dataverse table (or SharePoint list) to hold the data for populating the template.

Our example table, "Contract Details," includes:

  • Contract Name (Single Text)

  • Contract Value (Whole Number)

  • Start Date (Date)

  • End Date (Date)

  • Duration (Whole Number)

  • Description (Multi-line Text)

Building the Power App (Optional)

For this demo, we'll use a simple Power App ("ContractWise") to trigger the flow. It displays a list of contracts and their details. We'll add a button to trigger the flow and populate the contract template for the selected contract.

Creating the Power Automate Flow

  • Go to make.powerautomate.com and create a new Instant Flow.

  • Choose "When Power Apps calls a flow (V2)" as the trigger.

  • In the flow designer, add a Text Input to the trigger and name it "GUID". This will receive the ID of the contract item from the Power App.

  • Add a "Get a row by ID" action to retrieve the selected contract details from Dataverse using the GUID.

  • Add the "Populate a Microsoft Word template" action.

  • Specify the document location and select the template.

  • In Advanced Features, map the Content Controls to the corresponding columns from the Dataverse "Get row" action.

  • Add an action to handle the populated document (e.g., save to a location, generate a PDF, send for approval).

  • In this example, we'll use "Send an email (V2)".

  • Specify the recipient, subject, and body.

  • In Advanced Parameters > Attachments:

  • Add a new item.

  • Name: "Auto-populated Contract Document" (or use dynamic content from the Dataverse action).

  • Attachment: Select the "Microsoft Word Document" dynamic content from the "Populate a Microsoft Word template" action.

Integrating the Flow with the Power App

  • Open the ContractWise app and navigate to the Power Automate section.

  • Click "Add Flow", search for your flow, and add it to the app.

  • Select the Print button in the gallery and update the OnSelect property with the following code to trigger the flow and pass the item's GUID:

ContractGeneration.Run(ThisItem.'Contract Details')

Testing the Solution

  • Run the app, select a contract, and click the Print button.

  • Check your email for the auto-populated contract document.

That's it! You've successfully automated contract generation using Power Automate.

This is just one example; the possibilities are endless. Experiment with different triggers, actions, and data sources to streamline your document automation processes.

If you’d like to learn more about a specific section of this article, please reach out.

Next
Next

Convert Word files to PDF with Power Automate