Power Apps Exchange

Please login or click SIGN UP FOR FREE to create your PowerAppsUG account to join this user group.
 View Only
  • 1.  Embed Sharepoint List Photo Attachments to HTML/PDF and Email to End User

    Bronze Contributor
    Posted Jan 03, 2020 12:02 AM
    Hi All,

    Hope someone can assist with the following.

    I have an app that puts together a HTML report based on data drawn from several Sharepoint lists. There is one component that has stumped me, which is getting the photo attachments out of one Sharepoint list and putting them at the end of the HTML report.

    I wanted to use the json trick shared by Shane Young (https://www.youtube.com/watch?v=RFZfvTuDmP0&list=PLCGGtLsUjhm2bonhBZuEhZU72QkFjOpc6&index=71) to turn the attachments into base64 so that they can be embedded into the HTML, but this does not appear to work (or I am missing a step).

    The Sharepoint list photo attachments follow the format "appres://datasources/..." when copied to a local collection on the app I made, and I can display them properly in the App using the image control.

    When I try to apply the above value through Set(globalVar,JSON(<value>)), the format doesn't  change to base64 as expected (it remains as appres). Since the conversion doesn't work I just end up with broken images at the end of the HTML report due to the code "<img src="&globalVar&" style='width:100%;height:100%;'>".

    Anyone have any insight for this? Either something additive to the steps outlined above or an alternative strategy would be greatly appreciated.

    ------------------------------
    Zhi Rui Foo
    Operations Development Executive
    +65 6483 3335
    ------------------------------


  • 2.  RE: Embed Sharepoint List Photo Attachments to HTML/PDF and Email to End User
    Best Answer

    Top Contributor
    Posted Jan 03, 2020 06:45 AM
    Edited by Zhi Rui Foo Jan 06, 2020 01:28 AM
      |   view attached
    Hi Zhi,

    My take on Shane's process (which I currently use a variation of) is for saving pen input in SharePoint where the data is an image in PowerApps.
    Set(vImage,JSON(MyPenInput.Image,JSONFormat.IncludeBinaryData));
    Set(vImage,Mid(vImage,24,Len(vImage) - 24))
    produces a Base64 string, then in the PowerAutomate file content base64ToBinary(triggerBody()['Createfile_FileContent']) sends it to SharePoint.

    As you have noted, you have collected the data and displayed it. I am no expert on this, but as you know, Image controls will display a number of formats and Shane's code referred to .Image properties in the object being converted. This post may be useful to you to get the content another way, but I have not tried it. Also note (as below) dataUri format works in HTML embedded images.

    This may be helpful (or not), but I use a different process emailing signed forms (with the Pen Input), which are saved as JPGs in a SharePoint Library, so the principle is the same as your requirements.

    The process only sends the HTML body and file URL/s from PowerApps but has a fairly large Power Automate process (which I have attached) and will briefly run you though it (it also attaches the PDF to an email).
    MyPhotoFlow.Run( Image1_Path/Name, Image2_Path/Name, HTMLContent.HtmlText, FileName, SharePoint_Metadata1, SharePoint_Metadata2,EmailAddressToSendTo, EmailSubject, EmailBody );

    Firstly, note this is a test version where SharePoint and Email was added later, so you do not need the Delete OneDrive PDF, but the Create OneDrive PDF is needed if getting the file from there. The sequence for SharePoint email is:
    • Get the content of the Image/s from the SP Library.
    • Get the HTML Text in a Variable.
    • Get the File Name (useful in a Variable as two different extensions are used later on).
    • Convert image content to dataUri.
    • Use an Expression to concat the HTML text Variable with the bit containing the images (a HTML table used with content below).
    • Convert the HTML output to PDF.
    • Create OneDrive PDF (if not using SharePoint).
    The following I also do: -
    • Copy PDF to SharePoint with Metadata.
    • Delete the SharePoint HTML file.
    • Attach SharePoint PDF file to an email.

    As noted above the HTML Expression in mine (to put two signatures in a table) is (you only need the bold bits for yours): -

    concat(variables('HTMLPage'),'<table border="0" cellspacing="0" cellpadding="0"><tbody><tr><td width="250"><strong>Signature of Owner/Occupier</strong></td><td width="250"><strong>Ergon Signature</strong></td></tr><tr><td width="250"><img src="',variables('OwnerImg'),'" alt="Owner Signature" height="40" width="200"></td><td width="250"><img src="',variables('VentiaImg'),'" alt="Ergon Signature" height="40" width="200"></td></tr></tbody></table>')

    One thing to watch (as you would know) the HTML body text in PowerApps is surrounded by double quotes " with single quotes ' in the HTML. The concat in the expression is the opposite - concatenated parts are separated by single quotes with double quotes in the HTML, so "',variables('VentiaImg'),'" above is double-single at the start and single-double at the end. Fortunately HTML renders either as quotes.

    I hope this is useful

    ------------------------------
    Warren Belz
    Ventia Utility Services Pty Ltd
    Rockhampton Qld Australia
    +61 409 315 509
    ------------------------------

    Attachment(s)

    pdf
    PDFImages.pdf   966 KB 1 version


  • 3.  RE: Embed Sharepoint List Photo Attachments to HTML/PDF and Email to End User

    Bronze Contributor
    Posted Jan 06, 2020 01:45 AM
    Edited by Zhi Rui Foo Jan 06, 2020 01:45 AM
    Hi Warren,

    Thanks!

    Your post got me thinking about the root of the issue, which is what the HTML img tag takes in as a variable.

    Since URLs work, I went and found how sharepoint calls up attachments when you view them in a browser. Turns out the URL follows a standard format:

    https://<your_domain>.sharepoint.com/sites/<your_sharepoint_site>/Lists/<your_sharepoint_list>/Attachments/<ID_of_your_sharepoint_list_row>/<name_of_your_attachment_with_extension>

    I used the lookup() function to find the ID of the row I needed, and a combination of the Form Edit Control and ClearCollect() to make a local collection containing the attachment names (this was the trick I found originally to display photo attachments in a Power Apps gallery)

    The additional functionality I found useful with implementing the above is that I can give end users a preview of the HTML report on the app before they email/download it proper. I also avoided having to deal with the ' and " convention clash between Power Apps and Power Automate (ie I didn't need to re-write the Power Automate component attached to my Power App).

    ------------------------------
    Zhi Rui Foo
    Operations Development Executive
    +65 6483 3335
    ------------------------------



  • 4.  RE: Embed Sharepoint List Photo Attachments to HTML/PDF and Email to End User

    Top Contributor
    Posted Jan 06, 2020 02:22 AM
    Hi Zhi,

    I am glad this was of use to you.

    I can see now how your process is quite different in that you have the files as list attachments, whereas mine are stored in a separate Library, with Metadata in both the list and library to find "what belongs to what".

    I also give the users a graphical preview of what is about to be sent in HTML text, with the send button on the screen.

    When you mention avoiding the  ' and " convention clash between Power Apps and Power Automate, are you saying you generated the entire HTML for the PDF including the image dataUri/base64 content from PowerApps?






    ------------------------------
    Warren Belz
    Ventia Utility Services Pty Ltd
    Rockhampton Qld Australia
    +61 409 315 509
    ------------------------------



  • 5.  RE: Embed Sharepoint List Photo Attachments to HTML/PDF and Email to End User

    Posted Oct 20, 2022 01:25 AM

    Hi @Zhi Rui Foo

    Have you developed the flow? , I want to export the PDF of list items and their attachment images in a PDF​



    ------------------------------
    Mustafa Mohsin
    Associate Consultant
    Karachi
    ------------------------------



  • 6.  RE: Embed Sharepoint List Photo Attachments to HTML/PDF and Email to End User

    Posted Oct 20, 2022 01:58 AM

    Hi @Warren Belz

    I actually want to get the export of List Items along with their attachment images in a Html table format​

    can you please help me with that?



    ------------------------------
    Mustafa Mohsin
    Associate Consultant
    Karachi
    ------------------------------