web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Populate Multiple PNG ...
Power Automate
Answered

Populate Multiple PNG Attachments to a Microsoft Word Template from a Sharepoint List Item

(0) ShareShare
ReportReport
Posted on by 122

I have a flow with a PowerApps trigger. When the user selects a submit button, the flow should Populate a Microsoft Word Template with values from the selected Sharepoint List item, before creating a docx and pdf with those values to be stored in One Drive. Most of the fields are text, with the exception of Attachments. The flow should execute so that multiple PNG attachments from the selected Item of the Sharepoint List populate into Picture Content Controls in the Word Template.

 

I am trying to leverage the variables function in the Attachment1 field of the Populate a Microsoft Word template step in an expression to point to the index of the attachment to be populated, but receiving an error: The image is not of type PNG or JPG. Please provide an image of type PNG or JPG.

 

I've also tried leveraging the Attachment Content dynamic content value in the Attachment1 field, and the flow executes successfully, but it creates the docx and pdf files with the first PNG attachment file before immediately overwriting the file it just created with the second attachment instead.

 

Here are some screen shots from the flow:

 

jkb6011_0-1650579910886.png

jkb6011_1-1650579919108.png

jkb6011_2-1650579933652.png

jkb6011_3-1650579945238.png

 

If anyone could help me identify how to write these png files individually to the same Word Doc Template, I’d be forever in you debt!

Categories:
I have the same question (0)
  • Pstork1 Profile Picture
    68,717 Most Valuable Professional on at

    The problem is that you are trying to embed an array of attachment images rather than an image.  The Word Template can handle individual images using the image control, but not an array.  This thread shows how to do it for a single image.  How to populate a word document with images? - Power Platform Community (microsoft.com) For more than that your template will need one control per image. Or you'll need to pre-create the images as Rich Text and then embed them using a Rich Text control

  • Jay-Encodian Profile Picture
    2,920 on at

    Hey @jkb6011 

    The following approach covers this requirement: Add SharePoint List Item Data to a Document — Encodian

    Obviously this uses the Encodian 'Populate Word Document' action which is a third party connector (standard and not premium), so something to consider... there is free plan available

    HTH

  • jkb6011 Profile Picture
    122 on at

    I have seen and used this thread, but he is using Attachment Content in the Populate a Word Template attachment field. What code should be replaced with Attachment Content when there are multiple attachments to be added to a single word doc? @Pstork1 

     

    I also understand that I will need one control per image, but what code would I leverage to be able to point to the specific image I'd like to return?

     

    Like I said in my original post, "I've also tried leveraging the Attachment Content dynamic content value in the Attachment1 field, and the flow executes successfully, but it creates the docx and pdf files with the first PNG attachment file before immediately overwriting the file it just created with the second attachment instead."

     

  • jkb6011 Profile Picture
    122 on at

    Hey there Jay, Encondian isn't an option for me due to a lack of HIPAA Compliance.

  • Pstork1 Profile Picture
    68,717 Most Valuable Professional on at

    Its the same code he is using in the post.  You retrieve the document from wherever it is stored and then use the file content to fill in the image field in the Word Document.  The content will have two properties in a JSON object.  One will be the content type and the other is the content itself.

  • Jay-Encodian Profile Picture
    2,920 on at

    Hey @jkb6011,

    It it an option if you opt for a dedicated implementation, check out - https://support.encodian.com/hc/en-gb/articles/360008866798-Data-Security-and-Data-Privacy

    HTH

  • jkb6011 Profile Picture
    122 on at

    jkb6011_2-1650642234211.png

     

    jkb6011_4-1650642272421.png

     

    @Pstork1 , I changed the flow to initialize an attachment object, and then set the variable in the apply to each with the content type and content. But still running into errors when specifying the attachment to pull through an Expression..

     

    I've tried leveraging the body and variables functions below in the Populate a Micrsoft Word Template Attachment2 field to pull the specific PNG, but still running into issues.. Any insight as to how to correct my Expression would be very appreciated!

     

    body('Get_attachment_content')?['$content']
    variables('AttachmentObjects')

     

  • Jay-Encodian Profile Picture
    2,920 on at

    @jkb6011if you need to obtain just the base64 string value from a 'File Content' property you should use the base64() expression as opposed to referencing the $content element directly. Additionally I would advise using a string variable and not an object... as that's what base64 is.

    I would recommend reviewing the following video which explains how to work with files and variables: https://www.youtube.com/watch?v=zfVvCYXGcus

    Finally, your flow configuration will always write the last attachment into your object variable.... you are iteratively obtaining each attachment and then overwriting the same variable.

    If you use the MS Word connector you have to have a 1-2-1 mapping between the placeholder and the image... you cannot pass an array.

  • Pstork1 Profile Picture
    68,717 Most Valuable Professional on at

    If you look at the output of your get attachment content step you will find that the content is already an object with both the Content-type and the Content.  So you don't need to do the JSON you are doing.  But since you are doing it inside a loop you are overwriting each attachment as you process the loop.  Your variable when you try to insert it in the Template only has the last image and the object has the wrong information in it also.

  • Pstork1 Profile Picture
    68,717 Most Valuable Professional on at

    Adding it to the Word Template requires more than the BAse64 encoding.  You actually need the JSON object with both Content and Content-Type.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 525 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 324 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard