cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Eelman
Level 10

If() with Office365.SendEmail attachments

Using an If() statement, I'm trying to send emails which may or may not have attachments but it keeps telling me the attachments datacard cannot be null or empty:

 

Error: 

O365Email error.jpg

Code:

If(CountRows(DataCardValue44.Attachments)=0,

 

[then] Office365.SendEmail(myEmailAddress, "HTML & attachment", HTMLPOBEmail_1.HtmlText,{IsHtml: true}),

[else] Office365.SendEmail(myEmailAddress, "HTML & attachment", HTMLPOBEmail_1.HtmlText,{Attachments:Table({Name:"Septic Log", ContentBytes:First(DataCardValue44.Attachments).Value, '@odata.type':"" }), IsHtml: true}))

 

So, if the datacard has no attachment it fails, even though I've used an IF(). I thought the If() would stop at THEN but it appears to also check the ELSE for errors? I can use either the THEN or ELSE code as separate calls and they work fine it's just when they are bundle together they fail.

Note: The ELSE statement will fail if there is no attachments but works if there is...

 

Do I need to Remove then re-add back the O365 connector? If so, would this harm my App? This App is currently in use and emails are being used for other functions. This is just an extension of these functions.

 

Any help would be greatly appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
Eelman
Level 10

Re: If() with Office365.SendEmail attachments

This response is to help anyone else who has a similar issue as I managed to solve this myself.

 

Because the attachments are in a Form I found that if I reset the form before running the SendEmail code it works. Seems that CountRows(DataCardValue44.Attachments) = 0 can be true / false / or blank and when it was blank (which means no attachment) it was also false which would run the "add attachments option" code when it shouldn't have.

 

I add the following BEFORE the above code and it's working now:

ResetForm(myFormName); 

 

Hope this helps someone else.

View solution in original post

1 REPLY 1
Eelman
Level 10

Re: If() with Office365.SendEmail attachments

This response is to help anyone else who has a similar issue as I managed to solve this myself.

 

Because the attachments are in a Form I found that if I reset the form before running the SendEmail code it works. Seems that CountRows(DataCardValue44.Attachments) = 0 can be true / false / or blank and when it was blank (which means no attachment) it was also false which would run the "add attachments option" code when it shouldn't have.

 

I add the following BEFORE the above code and it's working now:

ResetForm(myFormName); 

 

Hope this helps someone else.

View solution in original post

Helpful resources

Announcements
thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Kudoed Authors (Last 30 Days)
Users online (5,754)