Forum Discussion

Leonel GUZMAN's avatar
Leonel GUZMAN
Brass Contributor
Jan 30, 2022

Reference "File" from "For a selected Item" in SharePoint

Hello

 

I got a SharePoint list (List A) where I run a "For a selected Item" event that collects text and a file (attachment) that I then use to populate a different list (List B).

 

I can use the text to populate List B through "Create Item", but I haven't been able to "Add attachment". I've looked for the answer, but I haven't understood how to reference the file content and the file name to use "Add attachment". 

 

The "For a selected Item" gives the outputs as shown below: "Testing flow", and ContentBytes and Name for the file, but I can't use them to "Add attachment". I will very much appreciate your help.

 

Leo

9 Replies

  • atifhafeez's avatar
    atifhafeez
    Copper Contributor
    To refer filename, use the following expression - triggerBody()?['file']?['name']
    To refer filecontent, use the following expression - base64ToBinary(triggerBody()?['file']?['contentBytes'])

    JPG Images are normally stored in binary format. Power automate returns the image data in base64 format. You are expected to convert the base64 file content to binary.

    Hope this helps
  • Sudharsan K's avatar
    Sudharsan K
    Iron Contributor

    Hi Leonel GUZMAN please refer the image and the steps below

    1. For a selected item you will be able to receive only few information, so you have to use some additional action to retrieve the attachment and then to save it to the new list.
    2. Get attachments action with the ID from the trigger action will get all the attachments of the selected list item
    3. The third action is to create a new item in the list b with the details you have, if you need additional list item metadata, you have to use Get Item with the ID from the trigger action.
    4. You have to loop through the attachments and inside the loop you have to use
      1. Get attachment content by passing the ID and File Identifier from the loop item
      2. Add Attachment by passing the Create Item action ID of the new item and then the content from the above action.

    Please try it out and let me know if you have any clarifications.

    • Leonel GUZMAN's avatar
      Leonel GUZMAN
      Brass Contributor

      Thank you very much Sudharsan K 

       

      The challenge I have is that List A doesn't have the attachment I need in List B. The only thing I get from List A is the ID, so that I can relate items in List B (Primary and Foreign Keys).

       

      In the "For a selected Item" action, I ask the user to give me new information: an Update (text), and an attachment (file). 

       

      I then create variables to use a) the text I get for the update, and b) the ID from List A, that I also use as a reference in List B. I haven't been able to use the input I get for file (Attachment (optional)).

       

      If I understand the use of "Get attachments" correctly, that action helps me get attachments from a list. However, I'm not trying to use attachments from the list, but the brand new file the user gives me through "For a selected item". This is the screen the user gets to provide the new input. The file in that new input is the challenge. I haven't understood how to use it and save it in List B.

       

       

      Thank you for your help.

       

Resources