Skip to main content

Notifications

Community site session details

Community site session details

Session Id : 99Ry81x22uKfhjHS5QYyYQ
Power Automate - Building Flows
Answered

Populating complex Word template

Like (0) ShareShare
ReportReport
Posted on 27 Apr 2021 16:33:56 by 54

Hello,

 

I have been working on trying to populate a complex Word template with data from several SharePoint lists, but am running into difficulty with repeating rows inside of a larger item.  I'm not sure if this is a limitation within Word or Power Automate, but I think my issue is within Power Automate, so I am sharing all info.  In Power Automate, the Populate a Word Template does not work within a For each loop or any other control. As long as the final file is a PDF, I do not have to use Word, if there is another option. 

 

For a singular project, I can populate: Title (single line of text), Description (multiple lines of text), Product List (repeating rows of "Product" and "Status"), plus more of the same.

 

What I cannot do is repeat all the items listed above for multiple projects within the same Word doc: having Title, Description and Product List for Title1, Title2, etc. 

 

Examples

Can doCan't Do

Title 1

Description 1

Products

Product A, Completed

Product B, In process

Product C, Not started

Title 1

Description 1

Products

Product A, Completed

Product B, In process

Product C, Not started

 

Title 2

Description 2

Products

Product A, Completed

Product B, Completed

Product C, In process

 

I have tried creating an HTML document then replacing the fields just like in Word, where [title] is replaced by TitleName - and this works until I need to repeat for all projects.  I have also tried writing my own JSON (which has been validated), and it works again until the whole project needs to be repeated for all projects in the SharePoint list. 

 

I'm not sure what specific information you all need to help.  I have searched online for similar items and tried to modify Flows from Reza Dorrani , Laura Rogers and many more.  Laura has a video on looping through a task list - which is great, but I need more than just the repeating rows and I need it all in one file, emails and not multiple files.

 

Thanks,

Cheryl

  • Community Power Platform Member Profile Picture
    on 21 Oct 2021 at 07:50:27
    Re: Populating complex Word template

    Hi there - could you please post your final flow to help out those who are trying to solve the same challenge?

     

    Thanks!

  • CCava Profile Picture
    54 on 02 Jul 2021 at 14:31:05
    Re: Populating complex Word template

    Thank you very much, @Pstork1! That was the last piece I needed to finish this - I would not have been able to navigate all the piece to this without your assistance - thank you again!

  • Pstork1 Profile Picture
    66,114 Most Valuable Professional on 01 Jul 2021 at 19:24:13
    Re: Populating complex Word template

    The first actions in the outermost loop should be actions that set all the variables.  You can clear an array variable by using the set variable action and setting it to null.  You can clear a string variable with the same action and setting it to string('').

    image.png

  • CCava Profile Picture
    54 on 01 Jul 2021 at 15:51:21
    Re: Populating complex Word template

    That definitely helped a lot - moving the book list loop inside of where I was getting the other information.  The (hopefully) last issue I am having is that the variable will not clear after each round in the loop. 

     

    varStays.png

     

    I've tried using a condition to see if the variable is null (using the expression editor), checking if the length of the variable is = 0, and in each appending the variable to null (using the expression editor) - and then not using a condition but still appending the variable to be null, '',  "", or even a space.  I sue the compose step to see what is in the variable at various times - and this is happening

     

    nullNotWorking.png

     

    I've tried placing the append to null (blank, '', "") at various points in the flow (beginning, end, before appending) - it never quite works.

     

    Is it possible to empty the string value between loops? Or is there another way to only show the active loop's data?

     

    I truly appreciate all of your help - thank you!

     

    Cheryl

  • Pstork1 Profile Picture
    66,114 Most Valuable Professional on 30 Jun 2021 at 20:21:10
    Re: Populating complex Word template

    If you want the list of books for each project in a section with each project then it has to be inside the loop where you are processing each project.  You can't do it in a separate place or the list won't appear at the right point in the file even if you do filter the list of books.

  • CCava Profile Picture
    54 on 30 Jun 2021 at 17:58:55
    Re: Populating complex Word template

    It is one file with a section for each project.  That's what I was trying to do - for each project, add only the titles that are part of that project.  Since the project titles and number of projects for each person are different, I need each of those to be dynamic. 

     

    To check if a book is part of that project, I would need a list of all books in each project - but that is what I am trying to get.  Here's what I've tried:

     

    condition1.pngcondition2.pngNow, this does remove the duplicates from my PDF, but still shows all book titles, even if they aren't part of the project.  It keeps appending the varProjBookList for all projects in the array.

     

    I tried "is equal to" instead of "contains" but that didn't work at all.

     

    I know it has to be the logic that I am using that is not producing what I am trying to get - but I'm not sure what I am missing?

     

  • Pstork1 Profile Picture
    66,114 Most Valuable Professional on 30 Jun 2021 at 16:47:10
    Re: Populating complex Word template

    Is the output of the flow one file with a section for each project or one file per project?  It sounds like its one section per project.  If that is the case I don't think you want the double loop where you are looping through the projects.  I think what you want at that point is a condition that checks each book to see if it is part of that project.  If it is add it, if it isn't skip it.  That should then be part of the overall project loop so you are appending each book list to the project as you are processing the project.

     

     

  • CCava Profile Picture
    54 on 30 Jun 2021 at 15:58:39
    Re: Populating complex Word template

    Hi, @Pstork1 ,

     

    Sorry it has taken me so long to get back on this - other higher priority projects came up.  This has mostly helped (I've been able to successfully add most parts into the string variables, concatenate them, create the file and view it) , but I am still not successful with one part of my request though: filtering a list for just the project listed. 

     

    In this report, I will have multiple projects that each have repeating rows sections (see example 1 below, data will match the screenshots for ease - please excuse my weird test data) - which I can get with what I created from your suggestions, but the data for the repeating rows section within each project is listing all data for all projects, not just the project it's part of (see image Results), so I tried to get the data a different way which somewhat works.

     

     

    Example 1

    Report for Cheryl C (will have a report for multiple researchers)

    ABC Reading Rainbow, active

    Some description of the project

    Staff on the project

     

    Book List

    Book TitleBook Author
    My Little PonyCool author
    Strawberry ShortcakeAnother author

     

    Outcomes List

    ItemDue
    Write paperJul 1
    Write bookOct 31

     

    123 Math Stories, active

    Some description of the project

    Staff on the project

     

    Book List

    Book TitleBook Author
    The little engine that couldRad person
    Best math stories everMath teacher
    Bedtime mathParentsR Us

     

    Outcomes List

    ItemDue
    Edit paperJul 15
    Edit bookOct 31

     

    Results

    Results.png

     

    My Flow

    flow-All.png

     

    Close up on appending book list variables which is the part not working how I want

    appendBookLists.png

     

    I tried filtering the data through Parse JSON then using Select to show only the fields I need then using Create HTML table - it still always lists the entire list, not just for that project.  Project title is the first column in the lists:

     

    testData.png

     

    I'd appreciate any help or insight you (or anyone else) can give into this  - Thanks!

     

    Cheryl

     

  • Verified answer
    Pstork1 Profile Picture
    66,114 Most Valuable Professional on 05 May 2021 at 20:01:23
    Re: Populating complex Word template

    There isn't really a trick.  Its a bit tougher because you are working with RAW HTML.  But I've hand coded enough web sites over the years in notepad.  Its the same thing.  Here's screenshots of the flow.

     

    1) Start the flow and get Base64 code for the two images I use in the HTML.

    image.png

    2) Create a bunch of other variables to hold different HTML fragments.  

    image.png

    The top of the document must have this HTML

    image.png

    The rest of the variables are HTML building blocks.  For example, here's the HTML fragment that starts the <Body> tag.  Dynamic content is applied where needed.  This header will only be used once in the document.

    3) Now that we have the building blocks for the top and bottom of the document its time to buildout the detail lines. I create a loop counter so I can alternate the background colors of the rows to make them more readable.  Then process each row using an Apply to each loop.

    image.png

    Odd versus even rows have slightly different styles but are otherwise identical.  Here's what an odd row looks like.  This inserts the dynamic content for that row and appends it to the Table Header variable.

    image.png

    4) Once all the rows are processed I close out the HTML table that I've been appending rows to.  Then I concatenate the various fragments together, create the HTML file in OneDrive, and Convert it to PDF in memory, and save the PDF file to OneDrive.

    image.png

  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on 05 May 2021 at 19:18:16
    Re: Populating complex Word template

    Hi @Pstork1 

     

    I'm interested 😂.  I've played with HTML to PDF in OneDrive and found the conversion hit and miss and had better luck with Word or Excel to PDF.  If there is a trick to getting the format correct I would appreciate you sharing the tip.

     

    Cheers,

     

    Damien

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 - Building Flows

#1
stampcoin Profile Picture

stampcoin 55

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 39 Super User 2025 Season 1

#3
VictorIvanidze Profile Picture

VictorIvanidze 26

Overall leaderboard