web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Email Attachment only ...
Power Apps
Answered

Email Attachment only when my collection isn't blank

(1) ShareShare
ReportReport
Posted on by

Hi, my app sends an email when everything is completed, and I would like to include the first photo from my 'photoattachments' collection as an attachment to the SendEmailV2 command. It is working fine with a code I created, but when the user don't take any photo, it gives an error. I tried to make an exception as below:

(...) If(CountRows(photoattachments) > 0 , {Cc:First(DRACollection).ProjectManagerEmail, Attachments: {Name: "RAMS - " & First(photoattachments).Name, ContentBytes: First(photoattachments).att,'@odata.type':""}},{Cc:First(DRACollection).ProjectManagerEmail})

 But it gives strange error messages, like e.map is not a function.

 

Could you please advise me the best solution to just avoid adding attachment to the email when the 'photoattachments' collection is empty? Thank you

Categories:
  • iAm_ManCat Profile Picture
    18,256 Most Valuable Professional on at

    Hi!

     

    You should have the check for attachments outside (further out) when doing the send like this:
    (please note this is pseudo code and you should fill it with the code you are already using to send the email)

     

    If(Countrows(photoattachments)>0,
     <OFFICE365Outlook SENDEMAIL CODE WITH ATTACHMENTS>,
     <OFFICE365Outlook SENDEMAIL CODE>
    )

     

  • Verified answer
    v-qiaqi@microsoft.com Profile Picture
    Microsoft Employee on at

    Hi @plona95,

    I have a test and the situation is confirmed on my side, I could send an email with the first attachment from the photoattachments when it is not empty, here is the formula I have tried:

    If(
     CountRows(photoattachments) > 0,
     Office365Outlook.SendEmailV2(
     "xxx@xxxx.onmicrosoft.com",
     "test",
     "hola",
     {
     Attachments: {
     Name: "RAMS - " & First(photoattachments).Name,
     ContentBytes: First(photoattachments).Value,//here you should reference to Value
     '@odata.type': ""
     }
     }
     )
    )

    I could not send any email or receive any error report if the photoattachments is empty.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 354 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 330

#3
Mohsin Ali Profile Picture

Mohsin Ali 232

Last 30 days Overall leaderboard