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

Brass Contributor

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.

 

Output.png

Leo

7 Replies

Hi @Leonel GUZMAN please refer the image and the steps below

SudharsanK_0-1643594591674.png

  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.

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). 

LeonelGUZMAN_4-1643597465168.png

 

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.

 

LeonelGUZMAN_1-1643597070266.png

 

Thank you for your help.

 

@Leonel GUZMAN did you get an answer, I have exact same issue.

@alirananavitascom 

 

Unfortunately not. I didn't I dropped the project.

I hope you have better luck.

 

lg

@Leonel GUZMAN sorry to hear you had to drop the project.

Not a good omen for me thinking of having Microsoft being able to actually solve any issue that their end users face. Its just so draining working on Microsoft products!!

@alirananavitascom@Leonel GUZMAN,

 

Please find below the solution I tried : 

Capture d’écran 2022-12-20 144656.png

 

I was not able to recover the filename with the flow, so I used this expression to get it from the attachement I uploaded manually :

string(triggerbody()?['file']?['name'])

 

It allows me to get the filename and store it in my SharePoint list.
Please let me know if it's ok for you.


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