Power Automate w Word Online: generate document updates

Scenario:

My client generates a summary document for applications lodged online. The generated summary could be manually edited by an officer. At the final stage of the application processing, it’s required to include additional information to the generated summary document regarding the outcome of the application. This information must be dynamically generated.

This is a process diagram below:

Power Automate w Word Online: generate document updates
Multi-step document generation

As you can see, the dynamic content for a document is generated twice: once during the document creation and a second time we update the existing document to add blocks of information that are not available at the earlier phase.

The solution:

We are going to use Power Automate with Word Online (Business) connector to generate and update the summary document.

There is an article explaining how to prepare the template and discussing some limitations of the connector: https://learn.microsoft.com/en-us/connectors/wordonlinebusiness/

Step 1. Prepare a document template.

We must add all the fields to the template including fields we are going to populate later.

Power Automate w Word Online: generate document updates
Add fields with unique names

I use Star/End tag for the Show As property to show you field names. Please use Bounding Box instead.

I uploaded the document template to OneDrive.

Step 2. Create a Power Automate flow to generate a summary (create)

We use Populate a Microsoft Word template action of the Word Online (Business) connector to populate the template.

For the Application record created the flow will be triggered. We make sure all the fields required for the first run are included in the action. Note the field Populate later is not populated. We keep it to be populated with the outcome at the second run.

Power Automate w Word Online: generate document updates
Generate document flow

For the sample application record

Power Automate w Word Online: generate document updates
A sample Application record
Power Automate w Word Online: generate document updates
Successful flow run

Document generated:

Document generated

The document is populated from the Application record. The outcome field remains unpopulated until the next run. This document now can be updated manually. Let’s add some content and then save.

Add manual content to the generated document

Step 3. Create a Power Automate flow to generate an outcome (update)

Before we start building the update flow, in the original flow add some text to the Populate later field. Click on  than Peek code.

Find the correspondent parameter for the Populate Later field. In my case, it’s “dynamicsFileSchema/1762023507”. Save it.

dynamicFileSchema parameter name

The second flow is triggered on a status change. If the status is Outcome Received.

Let’s see what’s inside!

Getting the Application number

We need to fetch the Application number to construct the correct file name.

ESPC call for speakers 2024
In the Populate a Microsoft Word template step/action we play a couple of tricks.

First, we construct the dynamic file name using the data we retrieved in the previous step.

Second, that dynamicsFileSchema we saved, remember?

Let’s construct a JSON like in the screenshot below, using the dynamicsFileSchema values as a key and Outcome retrieved for the record as a value.

Populate the updates

In the last step, we just update the file with the content from the generation step.

Power Automate w Word Online: generate document updates
Update flow

Let’s run the flow and see results!

Successful run

Hocus-pocus!

You could see the file content contains the details from the first run, the manual updates, and the second run updates.

You can find more great Power Platform related content on Power Platform Week.

The conclusion:

As we can see, it is possible to generate document updates populating dynamic values with the data which is not available yet during the document creation. Sounds like black magic but it works! 

About the Author:

My name is Olena Grischenko. I was born in Ukraine and live in Australia.

I am a Dynamics 365 consultant, working with Microsoft Dynamics CRM from version 1.2, for 17 years.

My favorite version of MS CRM, now we call it Dynamics 365, is always the latest one because the product is getting better and better each year.

So, for my past 20 years in the IT world, I am a CRM Technical Architect, a CRM Solution Architect, a CRM developer,  a .NET developer, a web developer, and a developer.

Reference:

Grischenko, O. (2022). Power Automate w Word Online: generate document updates. Available at: https://msolenacrm.blog/2022/09/28/power-automate-w-word-online-generate-document-updates/ [Accessed: 28th March 2023].

Share this on...

Rate this Post:

Share: