Power Automate, a robust tool from Microsoft, allows you to automate workflows between your favorite apps and services. One powerful use case is generating documents using Word templates and then making these documents available for download directly from a model-driven app. In this blog post, we will walk you through the steps to create a Power Automate flow that populates a Word template and downloads the result from a model-driven app.
Prerequisites
Before we begin, ensure you have the following:
1. Access to Power Automate.
2. A model-driven app in Microsoft Dynamics 365 or Power Apps.
3. A Word template prepared with content controls (placeholders) for the data you want to populate.
Step-by-Step Guide
Step 1: Create the Word Template
1. Open Word and Create a New Document:
– Design your template, including placeholders for the data you want to populate. These placeholders should be content controls (e.g., plain text content control).
2. Save the Template:
– Save your Word document as a `.docx` file and upload it to a SharePoint document library or OneDrive.
Step 2: Create the Power Automate Flow
1. Log in to Power Automate:
– Navigate to [Power Automate](https://flow.microsoft.com) and sign in with your credentials.
2. Create a New Flow:
– Click on Create in the left-hand navigation pane.
– Select Automated cloud flow.
3. Define the Trigger:
– Choose a trigger that suits your use case. For example, “When a record is selected” in a model-driven app.
4. Add a Step to Get Template:
– Add a new step and search for SharePoint (or OneDrive).
– Select the action Get file content and specify the location of your Word template.
5. Add a Step to Populate the Template:
– Add another step and search for Word Online (Business).
– Select the action Populate a Microsoft Word template.
– Choose your Word template and map the fields from your model-driven app to the content controls in the template.
6. Add a Step to Create the File:
– Add a new step and search for Create file (this could be in SharePoint or OneDrive).
– Specify the location where you want to save the populated document.
7. Add a Step to Download the File:
– Add a final step and search for HTTP.
– Use the action Get file content again if needed to retrieve the created document.
– You may need to construct a download link or return the file content depending on how you want to handle the download in your app.
8. Save the Flow:
– Give your flow a name and save it.
Step 3: Integrate with the Model-Driven App
1. Open Your Model-Driven App:
– Navigate to the app designer in Power Apps.
2. Add a Custom Button:
– Add a custom button to the relevant form or view in your app.
– Configure the button to trigger the Power Automate flow you created.
3. Test the Flow:
– Select a record in your model-driven app and trigger the flow using the custom button.
– Ensure the Word template is populated correctly and the document is available for download.
Conclusion
By following these steps, you can create a seamless experience for users to generate and download documents directly from a model-driven app. This integration between Power Automate and model-driven apps can significantly streamline document generation processes and improve efficiency.