cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
noobi
Helper I
Helper I

Send E-Mail only once

Dear community,

 I have the following formula by selecting a Button:

 

Patch(MitarbeiterdatenTasks;First(Filter(MitarbeiterdatenTasks;Title=Label3.Text));{Task: 1});;

 

  I want to send an E-Mail if all values in column Task are set to 1, which I do by this:

 

If(CountRows(Distinct(MitarbeiterdatenTasks;Task="1"))=1;
Office365Outlook.SendEmail("xxxxx@xxx.com";"Tasks Completed"; "I finished my tasks");
false);;

 

My Problem is that if the user clicks the button again another E-Mail is sent. I would like to send the E-Mail only once.

Can anybody help me?

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
iAm_ManCat
Super User
Super User

This really depends, do you want it to only happen once forever, or only once while they are using the App?

 

If its only while they are currently using the App:

 

If(CountRows(Distinct(MitarbeiterdatenTasks;Task="1"))=1 && EmailSent=false;
Office365Outlook.SendEmail("xxxxx@xxx.com";"Tasks Completed"; "I finished my tasks");
false);;
Set(EmailSent; true)

 

If you want it to only send one forever, then you'll want to create a new list or have a column in your parent list called 'EmailSent', which you can set to true by patching it when you send the email, then make the email only send if that is false..

 

Also be careful using Distinct - I'm not sure what your datasource is, but Distinct could eventually stop working if its susceptible to delegation limits, as it will only work within the delegable limit (the max of which is currently 2000 when set in the settings of your App)

@iAm_ManCat


Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


View solution in original post

4 REPLIES 4
adgkred
Resolver III
Resolver III

Hey @noobi

 

I think that an easy way to fix this would be to add a variable. On the app "OnStart" property you can set a var like that:

Set(EmailSent, 0);

 

Then on your If you can add a second condition:

If((CountRows(Distinct(MitarbeiterdatenTasks;Task="1"))=1) && (EmailSent = 0);
Office365Outlook.SendEmail("xxxxx@xxx.com";"Tasks Completed"; "I finished my tasks");;Set(EmailSent,1);false);;

 

The first time a user click on the button the email will be sent if the conditions are met, but after that it shouldn't send any more emails since the variable won't be equal to 0 anymore.

iAm_ManCat
Super User
Super User

This really depends, do you want it to only happen once forever, or only once while they are using the App?

 

If its only while they are currently using the App:

 

If(CountRows(Distinct(MitarbeiterdatenTasks;Task="1"))=1 && EmailSent=false;
Office365Outlook.SendEmail("xxxxx@xxx.com";"Tasks Completed"; "I finished my tasks");
false);;
Set(EmailSent; true)

 

If you want it to only send one forever, then you'll want to create a new list or have a column in your parent list called 'EmailSent', which you can set to true by patching it when you send the email, then make the email only send if that is false..

 

Also be careful using Distinct - I'm not sure what your datasource is, but Distinct could eventually stop working if its susceptible to delegation limits, as it will only work within the delegable limit (the max of which is currently 2000 when set in the settings of your App)

@iAm_ManCat


Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


Hello Mr. iAm_ManCat,

 

thank you for the answer. Your descripted solution is exactly how I solved the issue. 

Sorry for the inconvenience. 

Best Regards

No worries! Happy you got it solved! 🙂

@iAm_ManCat


Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Power Apps Ideas

Check out the New Ideas Site

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (5,264)