cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
emfuentes27
Advocate II
Advocate II

Populate Word Template with nested (multilevel) Repeating Section Content Control

Is it possible to populate a Word Template that contains a nested or multilevel Repeating Section Content Controls. I have this data that I get from SharePoint, and the result is a JSON that looks like this:

 

 

[
  {
    "ro": "Billings",
    "tracking_repeat": [
      {
        "issue": "xxxx",
        "tracking": "xxxxxx",
        "rType": "xxxxxxx"
      },
      {
        "issue": "yyyyyy",
        "tracking": "yyyyyy",
        "rType": "yyyyyyy"
      }
    ]
  },
  {
    "ro": "Oklahoma City",
    "tracking_repeat": [
      {
        "issue": "aaaa",
        "tracking": "aaaaa",
        "rType": "aaaaa"
      },
      {
        "issue": "bbbbbb",
        "tracking": "bbbbb",
        "rType": "bbbbbb"
      },
      {
        "issue": "ccccc",
         "tracking": "cccc",
        "rType": "ccccc"
      }
    ]
  },
  {
    "ro": "Raleigh",
    "tracking_repeat": [
      {
        "issue": "dddddddd",
        "tracking": "eeeeeee",
        "rType": "ffffffffff"
      },
      {
        "issue": "ggggggg",
        "tracking": "hhhhhhhh",
        "rType": "iiiiiiii"
      }
    ]
  },
  {
    "ro": "Spokane",
    "tracking_repeat": [
      {
        "issue": "jjjjjj",
        "tracking": "kkkkkkk",
        "rType": "lllllll"
      },
      {
        "issue": "mmmmmmm",
        "tracking": "nnnnnnn",
        "rType": "nnnnnn"
      }
    ]
  }
]

 

 

I need to insert that data into a Word document templated with two Repeating Section Content Controls. The first repeating section would show the "ro", and then below it the data need to be inserted. It should look like this:

 

Annotation 2021-04-26 104637.jpg

So far I'm able to repeat the "ro", but the rest it shows as JSON. This is how the Word template looks like:

Annotation 2021-04-26 104637.jpg

I would appreciate any lead on this. Thanks in advance.

2 REPLIES 2
NiloferA
Responsive Resident
Responsive Resident

  1. Hi!

    Yes you can populate nested Repeating Content Controls in Power Automate, but the way you have the Repeating Controls Configured, your output will look something like this

     

    NiloferA_0-1619556270476.png

     

    Instead, use only one Repeating Section surrounding a Row and fill the fields conditionally in the Flow, the output will look something like this

    NiloferA_1-1619556360640.png

     

    In any case, below are the steps to follow in Power Automate to pass the correct Array to the Word Document for population of data

    1. Initialize an Array (myArray) and a String Variable (PreviousRO)
    2. Pass the JSON to Parse JSON action and generate the Schema
    3. Add an Apply to Each (Main) action and pass "Body" as the Input (Output from Parse JSON)
    4. Add an Apply to Each (Inner) nested inside the Apply to Each action added in step 3, and pass "tracking_repeat" as input
    5. Add a condition within the nested Apply to Each --> PreviousRO (variable) is equal to ro (items('Apply_to_Each_Main')['ro'])
      1. NiloferA_2-1619557372301.png
    6. In Yes Branch, add an Append to Array action and configure it as follows
      1. NiloferA_0-1619557629722.png

         

    7. In No Branch,
      1. Add Set a Variable action and set PreviousRO to ro (items('Apply_to_Each_Main')['ro'])
      2. Add an Append to Array Variable and Configure it as shown in below image
      3. Add another Append to Array Variable and Configure it as shown in below image
      4. NiloferA_1-1619557796621.png
    8. Add Populate a Microsoft Word Template action, select the Site, Library and the Template you wish to update
    9. You will get a repeating section corresponding to the one added on the template, pass the Array here
      1. NiloferA_0-1619559077762.png

         

    10. Add a Create file action to create a file in SharePoint with the newly generated content and pass the output from step 9 in File Content
      1. NiloferA_3-1619558027572.png

         

    *Please note, the key you enter in the Array should correspond to the Title of the Content Controls added in the Word Document.

     

    Hope this helps! Please post a Reply in case if you still face any issue.

Thank you! Do I understand correctly that for this to work we basically need to construct a "flat" array where nested elements follow each other? I mean like this:

 

[
  {
    "ro":"Spokane"
  },
  {
    "issue": ""
    "tracking": ""
    "rType": "",
  },
  {
    "issue": ""
    "tracking": ""
    "rType": "",
  },
  {
    "ro":"Raleigh"
  },
  {
    "issue": ""
    "tracking": ""
    "rType": "",
  },
  ...
]
 

 

 

Update: I tried this and can't get it to work. The flow fails with a "Bad Request" error when trying to populate the Word template. That error seems to be caused by bad input since it goes away when I change the input structure to a nested object (though the Word document content is not populated correctly in that case).

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (3,131)