cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
olacharles
Frequent Visitor

How to get the first attachment on a SharePoint list item

Dear community,

I am currently working on a flow and need to get the first attachment file out of the multiple files attached to a SharePoint list.

 

My flow is typically like this

Get attachments >>> Get Attachment Content >>> then send email with the attachment content.

 

My flow will run and I will get different emails for every attachment on the list meanwhile I needed the first attachment file and not others.

 

It is frustrating and I need help right now.

1 ACCEPTED SOLUTION

Accepted Solutions
tom_riha
Super User
Super User

Hello @olacharles ,

you can use the First() expression to get the 'Id' of the first item in the collection of attachments provided by the 'Get attachments' action. Then apply the 'Get Attachment Content' only on the 'Id' of the first item, without 'Apply to each'. 

First(outputs('Get_attachments')?['body'])?['Id']

 image.png



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

View solution in original post

4 REPLIES 4
abm
Super User
Super User

Hi @olacharles 

 

After the get attachments step you will have a loop which will retrieve all the attachments.  You could use a Do until loop or an IF condition with an incremented counter to stop iterating the next attachment. Inside your Do Until Loop or the IF condition (where counter = 1) do the attachment content extraction action steps.

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blogPower Automate Video Tutorials
tom_riha
Super User
Super User

Hello @olacharles ,

you can use the First() expression to get the 'Id' of the first item in the collection of attachments provided by the 'Get attachments' action. Then apply the 'Get Attachment Content' only on the 'Id' of the first item, without 'Apply to each'. 

First(outputs('Get_attachments')?['body'])?['Id']

 image.png



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

View solution in original post

Thank you so much @tom_riha . this works perfectly well!

Many thanks for this!

    This works well, but what if in the trigger, we wanted an input to select which file we wanted to rename? For example, an input can have "2", and then, instead of "first(outputs...)" to get the first file, it would be "second(outputs...)", or something equivalent? Adding the input and reading it is fine, but would anyone know the syntax to select a specific file? I would prefer not to use an Apply To each loop.

Thank you, in advance!

 

Steve in Spain

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (1,441)