Skip to main content

Notifications

Community site session details

Community site session details

Session Id : TIrkvZLSI4SiXgOYEj4zmQ
Power Automate - General Discussion
Answered

Populate Word Template: How to use dynamic files (dynamicFileSchema)

Like (2) ShareShare
ReportReport
Posted on 8 Sep 2020 16:21:02 by 4
Hi,
I'm using the Premium Populate Microsoft Word Template with a PowerApps instant trigger. I want my template file name to be derived dynamically. The connector requires I pass a "dynamicFileSchema" field of type dynamic. I cannot find an example online or in documentation. Can someone please demonstrate how this works? I tried passing JSON and plain-text but it fails.
  • ehoward1 Profile Picture
    2 on 11 Jul 2024 at 13:59:22
    Re: Populate Word Template: How to use dynamic files (dynamicFileSchema)

    PowerAutomate1.pngPowerAutomate2.pngI was able to get this to work with images by creating a string variable from the GetFile of the image and adding a few lines in the dynamicFileSchema on the populate template action.

  • OheneSiaw Profile Picture
    25 on 22 Apr 2024 at 10:55:50
    Re: Populate Word Template: How to use dynamic files (dynamicFileSchema)

    Hi RichFunk365,

    Thank you for this. it worked for me. However, how do I do this with images.

  • Jan Simonsen Profile Picture
    16 on 20 Mar 2023 at 14:00:45
    Re: Populate Word Template: How to use dynamic files (dynamicFileSchema)

    Remember to use the XMLify function on contents the document.xml file before running the Xpath query on it.

     

    But perhaps your detour around JSON has the same effect. 🙂

  • raf-avag_99 Profile Picture
    132 on 20 Mar 2023 at 13:08:48
    Re: Populate Word Template: How to use dynamic files (dynamicFileSchema)

    Was having real trouble with the xpath for some reason. Had to convert xml to json then back to xml to make it work, and a Do Until to merge each Excel's row element into the schema. I though this was hopeless, but somehow managed to make it work (albeit it is a complex and ugly solution).

    Thanks for the input.

  • Jan Simonsen Profile Picture
    16 on 15 Mar 2023 at 14:11:44
    Re: Populate Word Template: How to use dynamic files (dynamicFileSchema)

    Hi

     

    It's a rather complex flow/flows, but i'll try my best to explain it. 🙂

     

    It goes something like this...

     

    Preparing template:

    1. The user uploads a file (Word merge template) to a file field in a "Templates" entity in CRM
    2. A cloud flow transfers the file to onedrive, unzips it and fetches the "word/document.xml" file from onedrive
    3. The flow then runs the following xpath query against the contents of "word/document.xml":
      //*[local-name()="tag"] | //*[local-name()="id"]
    4. This returns alternating results of merge field names and merge field ids which are then composed to a JSON-string in the form:
      { "-613740036": "field1", "-545143976": "field2", "1333568856": "field3", "1877353822": "field4", "-750961460": "field5"}
    5. The JSON is then saved in the "Templates" entity along side the word template for later use 

    Merging:

    1. Before merging a flow reads the dynamicFileSchema from the "Templates" entity into a variable and replaces the merge field names with the corresponding values from the data that is to be merged. 
    2. The dynamicFileSchema variable is then used as input for the Populate a Microsoft Word template"-connectors dynamicFileSchema field

    The composing of the JSON-string is a little complex in my solution - I'm sure it could be done easier. Even the xpath-query can probably be optimized, but I got it working so... 🙂

  • raf-avag_99 Profile Picture
    132 on 14 Mar 2023 at 08:59:11
    Re: Populate Word Template: How to use dynamic files (dynamicFileSchema)

    Could you please elaborate how do you extract mergefields dynamically from word? I'm at the point where I only need to get those fields as JSON dynamically

  • NyomanLukas Profile Picture
    18 on 21 Dec 2022 at 09:24:06
    Re: Populate Word Template: How to use dynamic files (dynamicFileSchema)

    @MatthewBrooksST, thanks for validating!

    @RichFunk365, thanks for coming up with this idea!

  • Jan Simonsen Profile Picture
    16 on 04 Dec 2022 at 22:27:27
    Re: Populate Word Template: How to use dynamic files (dynamicFileSchema)

    Hi 

    Old post, but wonder if you ever found a solution?

    I've build a solution that extracts mergefields from a word template to a json string with pairs of field id and name, then replaces the merge field names with actual data from CRM and uses it as a dynamicFileSchema for the Populate a Microsoft Word template"-connector.

  • Ankit7 Profile Picture
    3 on 21 May 2022 at 22:38:28
    Re: Populate Word Template: How to use dynamic files (dynamicFileSchema)

    I am facing the issue myself. I need to populate few word templates and I thought it should have been real simple but looking like it will take them some time to fix

  • JGrigar Profile Picture
    16 on 25 Jan 2022 at 11:13:58
    Re: Populate Word Template: How to use dynamic files (dynamicFileSchema)

    It's real shame for Microsoft that even after 2 years it is still implemented so ugly and not corrected

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Automate - General Discussion

#1
rpersad Profile Picture

rpersad 16

#2
David_MA Profile Picture

David_MA 10 Super User 2025 Season 1

#3
Michael E. Gernaey Profile Picture

Michael E. Gernaey 8 Super User 2025 Season 1

Overall leaderboard