cancel
Showing results for 
Search instead for 
Did you mean: 
WarrenBelz

Send selected attachments on an email directly from Power Apps

Have you ever wanted to send only some of the attachments on your record via email to someone? The solution is actually quite straightforward, but requires a bit of trickery not evident in the picture below.

AttachEmail.jpg

The attachment control is a standard item in a form displaying the attachments on a record (I called this one acEmail ) - there are no modifications to it. The check boxes shown however are in a gallery placed "on top" of the attachment control - I called it galAttach here. You may have to adjust the TemplateHeight to get it to "line up" properly with the attachment control. 

The Items of this gallery are

acEmail.Attachments

essentially a copy of the data in the attachment control.
Two labels are then inserted into the gallery with ThisItem.Name and ThisItem.Value and then hidden. A checkbox is then inserted (I called mine ckChoose) - it does not need to bound to anything.
Now the email button uses the Office365Outlook Connector (so attach it in your data sources) with the following OnSelect

Office365Outlook.SendEmailV2(
   "xxx@yyy.com",
   "Subject here",
   "Attached are the chosen files",
   {
      Attachments: 
      AddColumns(
         RenameColumns(
            Filter(
               galAttach.AllItems,
               ckchoose.Value
            ),
            "Value",
            "ContentBytes"
         ),
         "odata.type",
         ""
      )
   }
)

and it picks the values from the gallery (which has the same values as the attachment control), and attaches the content to the email.

 

Comments

Hi @WarrenBelz 

Itried your solution, but there is an error on the code.

Thanks mate @WarrenBelz 

@Yonatan_Harari ,

Please re-check your process and post on the forum if there is an issue - the code is valid providing the values you use are also.

I always get this error message back if I send the mail:

 

The "Attachment Content" parameter cannot be null or empty

Hi Warren, 

I like this and trying it out for a solution for my workflow.

I am getting error from the "Value", "ContentBytes" (assume this is inside RenameColumns() ) all the way to closed parentheses at the end?

 

Any assistance would be great

 

Cheers Craig

Hi Craig,

That is straight code for an email - I am not sure how it would function in a workflow.

Hi Warren, 

Yes, my mistake, I am trying to run this from Power Apps button where it picks up the relevant patient detail (PatientSearchList.Selected.Patient Name) and Date or Birth (PatientSearchList.Selected.DOB) to add to the body of the email, creates the email as per your code and adds the ckChoose  Attachment to the email all from within the APP. The email TO: would be PatientSearchList.Selected.Pharmacy.

 

is this how it should work?

 

Ta Craig

We might take this back to the forum - discussions tend to "clog up" a blog post. You really only need to add those two details to the To: and Body - you might provide your current code also.