cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
thunter
Post Prodigy
Post Prodigy

UpdateContext to send Emails

I am trying to use the UpdateContext function to send emails. I am getting an error when I click submit button on my form. Anyone know if I am using the UpdateContext correctly. Thank you!

powerapps2.jpg

Here is my formula:

 

UpdateContext({e:If(DeptTxt.Text="Office","clericaltimeoff@xxxx.com", If(DeptTxt.Text="Operations","dispatchtimeoff@xxxx.com", If(DeptTxt.Text="Maintenance","mowens@xxxx.com", If(DeptTxt.Text="Management","managertimeoff@xxxx.com"))))});

Office365.SendEmail(e,"Time Off Request", "<b>Time Off Request for " & UserName.Text & "<br></b>" & "Department: " & DeptTxt.Text & "<br>" & "Date Submitted: " & TodaysDate & "<br><br>" & "Start Date: " & StartDate & "<br>" & "Start Time: " & StartTime.SelectedText.Value & "<br><br>" & "End Date: " & EndDate & "<br>" & "End Time:" & EndTime.SelectedText.Value & "<br><br>" & "Time Off Code: " & TimeOffRadio.SelectedText.Value & "<br>" & "Description: " & BriefDescription & "<br>" & "<br><br>" & "<b>REQUIRED FOR HOURLY EMPLOYEES</b>" & "<br>" & "Paid Compensation: " & Radio4.SelectedText.Value & "<br>" & "Makeup Time: " &  Radio4_1.SelectedText.Value & "<br>" & "Makeup Hours: " & MakeupTime.Text & "<br>" & "Makeup Date: " & MakeupDate & "<br>" &  "<br>" & "Go to the MANAGER screen to Approve/Reject the Time off Request" & "<br>" & "https://apps.powerapps.com/play/fa97404b-6670-4390-880a", {IsHtml: true});

Office365.SendEmail(User().Email, "Time Off Request Submitted", "Your Time Off Request has been submitted successfully.", {IsHtml: true});

SubmitForm(RequestForm);
ResetForm(RequestForm);
Navigate(LogoutScreen,ScreenTransition.Fade)
1 ACCEPTED SOLUTION

Accepted Solutions

@thunter 
I think you should be using the function Office365Outlook.SendEmailV2 instead of Office365Outlook.SendEmail.

 

Can you please try that and let me know the result?  Also, do you have the Office365Outlook connector added to the app?

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

8 REPLIES 8
mdevaney
Super User
Super User

@thunter 
This code is massive.  Are you able to isolate the error?  Trying removing sections of the code to figure out what works and what doesn't.

 

Also, is it possible that none of your conditions in UPDATECONTEXT are being met resulting in a blank email?

 

 

One suggestion I have is to make your UPDATECONTEXT more readable by using SWITCH instead of nested IF statements.

UpdateContext({
    e: Switch(DeptTxt.Text
        "Office","clericaltimeoff@xxxx.com",
        "Operations","dispatchtimeoff@xxxx.com",
        "Maintenance","mowens@xxxx.com",
        "Management","managertimeoff@xxxx.com"
})

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

@mdevaney 

 

I ran the app using the Monitor tool to see if that would help. I have attached the data. It shows on line 35 of the Monitor report  a Bad Request. Any ideas? Thank you.

 

 

@thunter 

The problem appears to be with the 'createRow' open so maybe it has to do with submitting the form.

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

@mdevaney 

 

I removed my data sources and then saved, and then re-added data sources to see if that would fix the problem. Now the only error i have is: Invocation of unknown or unsupported function on the SendEmail formula

 

powerapps3.jpg

@mdevaney 

 

I did some reading and found out the connector I was using Office365.SendEmail, was incorrect. It should be Office365Outlook.SendEmail. So now I have no errors showing, however, it still is not successful when clicking Submit button. Still have the Bad Request. Also, the App Checker shows zero errors in formulas. Strange....

@thunter 
I think you should be using the function Office365Outlook.SendEmailV2 instead of Office365Outlook.SendEmail.

 

Can you please try that and let me know the result?  Also, do you have the Office365Outlook connector added to the app?

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

@mdevaney 

 

Does the Office365Outlook.SendEmailV2 connector work differently?

@thunter 

Yes.  Additionally, V1 is deprecated so it could be removed at any time.

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

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.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (4,010)