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:

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.

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.

For the sample application record


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.

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.

The second flow is triggered on a status change. If the status is Outcome Received.
Let’s see what’s inside!

We need to fetch the Application number to construct the correct file name.
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.

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

Let’s run the flow and see results!

Hocus-pocus!

You could see the file content contains the details from the first run, the manual updates, and the second run updates.
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! 🧙♀️
Reblogged this on MG and commented:
Update generated word template
LikeLike
is there a limit to the number of tables that use the Repeating Section Control?
LikeLike