Skip to main content

Notifications

Community site session details

Community site session details

Session Id : eacF809ttithMK52Ofj0rw
Power Automate - General Discussion
Answered

Feeding "Populate a MS Word Template" output to a variable

Like (1) ShareShare
ReportReport
Posted on 31 May 2023 18:17:44 by 31

Hello!

 

I am struggling with the following problem: In the flow below, I am using the "Populate Word Template" Action, which outputs the following:

 

Jhonny_Nassif_1-1685556578483.png

 

When I use the "Create File" (sharepoint) action and feed the output of the "Template" action directly into its "file content" field, it works fine.

 

The thing I am trying to do is feed the output from the "Template" action into a clean array variable first, and then feed the variable to the "Create File" action.

 

The file is created this way, but is corrupted and cannot be opened.

 

Below is a print of the flow:

 

Jhonny_Nassif_2-1685556837191.png

 

It corrupts the document when I replace the "Word Body" with the array variable.

 

Can anyone share some insights on what I am doing wrong?

 

Thanks in advance!

  • Verified answer
    Jhonny_Nassif Profile Picture
    31 on 01 Jun 2023 at 13:22:18
    Re: Feeding "Populate a MS Word Template" output to a variable

    Tried that before... the problem is that the variable must be STRING in order to be selectable as dynamic content for the "file content" field of the "Create File" action.

     

    And, being a string variable, the output of the "template" action doesnt show up in the dynamic content of the "set variable" action, as the output is seen as an array.

    The point of all this is because I have a switch action that selects a template depending on a FORMS answer.

     

    My goal is to put these templates outputs all in the same variable (depending on which template was selected by the switch) and then have a single "create file" action with the variable, after the switch action,

     

    Instead, I could build one "create file" action for each template inside the switch after each template, but this feels extremally suboptimal. Nevertheless, I feel like this is going to be the way to go, unfortunately...

     

    Thanks very much for the help, and I am more then willing to explore any other suggestions you may have!

     

     

  • AWorley Profile Picture
    414 Super User 2024 Season 1 on 31 May 2023 at 20:00:00
    Re: Feeding "Populate a MS Word Template" output to a variable

    What happens if you just place the output of the template action in the variable out right instead of renaming it to Body/Content? 

     

    Typically templates require several pieces of information to apply the values proper. Appending the content would not typically contain the template schema. 

  • Jhonny_Nassif Profile Picture
    31 on 31 May 2023 at 19:29:26
    Re: Feeding "Populate a MS Word Template" output to a variable

    Thank you, @AWorley , for the fast and insightful reply.

     

    I tried the following:

    Jhonny_Nassif_0-1685561147695.png

    As you can see, I simply renamed the action and used your suggested expression to feed the contents into the string variable.

     

    But, for some reason, the expression outputs blank:

    Jhonny_Nassif_1-1685561303912.png

     

    Which is curious, as the "TemplateM001" action returns the following schema:

    Jhonny_Nassif_2-1685561372460.png

    Can you provide any additional insights?

     

    Thanks!

  • AWorley Profile Picture
    414 Super User 2024 Season 1 on 31 May 2023 at 18:47:06
    Re: Feeding "Populate a MS Word Template" output to a variable

    You need to pass the "content" variable from the body instead of the Body itself, as the content is expected to be a string? 

    I believe the expression would be : outputs('Populate_a_Microsoft_Word_template')?['body/content']

     

    Also when i load that action I do not have access to the body attribute itself but the 

     

    AWorley_0-1685558779130.png

     

     

    Also I noticed that you are passing the Body attribute both in the array value and the Create file. So you may want to do the array value instead of Body. 

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!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,668 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,004 Most Valuable Professional

Leaderboard
Loading started