Populate a Microsoft Word Template with Dynamic Values (Power Automate)

Issue:

In Power Automate Cloud Flows, the Populate a Microsoft Word template action is commonly used to generate documents by inserting dynamic data into predefined Word template controls. However, this action has a practical limitation: Dynamic template fields are not exposed unless the user explicitly selects the SharePoint Site Address, Document Library, and Template File within the action configuration.

For example, in below screenshots we must select Location, Document Library and File. After selecting these 3 values dynamic template fields will get exposed.

This creates a challenge in scenarios where the template location or file needs to be determined dynamically at runtime, or when organizations want to build more reusable, environment-independent flows. Without manually selecting these parameters in the designer, the action does not surface the template placeholders, making it difficult to pass dynamic values and automate document generation in a flexible way.

As a result, flow developers often face issues such as:

  • Reduced reusability of flows across environments
  • Dependency on hardcoded SharePoint locations
  • Limited support for dynamic template selection
  • Extra maintenance effort when templates are moved or updated
  • Difficulty designing scalable document automation solutions

Solution:

This issue can be solved using Environment Variables and Json Payload.

How to pass dynamic values?

  • Create 3 environment variables, to hold Location, Document Library and File values.
  • 1st Location environment variable will be of type Site. Select SharePoint site where Document template is stored.
  • To get other 2 text environment variable values, initially select file in Populate a Microsoft Word Template action, then click on 3 dots. Click on Pick Code, you can see drive and file Id which can be added in environment variable.
  • In Populate a Microsoft Word template action, select environment variables. All dynamic fields for that template will get exposed. Fill those fields with required values. Then again go to pick code, you will find out Dynamic field numerical values.
  • Use these dynamic numerical field values to create Json like below and set it in Populate a Microsoft Word Template action:
  • This JSON will be common across all replicas of the document templates. In other words, if multiple copies of the templates are placed in different locations for each environment, the JSON schema will remain the same; only the environment variable values will change.

Leave a Reply

Up ↑

Discover more from Customizers

Subscribe now to keep reading and get access to the full archive.

Continue reading