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 blog
Power 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. ]

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
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Users online (2,854)