cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
oliviasoell
Frequent Visitor

Multiple Conditions to Send an Email

Hi, I am trying to send a email based off of multiple conditions. In order for an email to be sent, the status is not complete, and it is 5, 3, or 1 day before the due date. I have figured out how to do these conditions individually, but I am not sure how to put them together since the first condition is an "and" (the task cannot be marked as complete) and the second condition is an "or" (it is 5, 3, or 1 day before due date). I have attached my current flow below, which has been popping up with an error that says

"Flow save failed with code 'InvalidTemplate' and message 'The template validation failed: 'The repetition action(s) 'Apply_to_each' referenced by 'inputs' in action 'Condition_2' are not defined in the template.'."

Any help would be appreciated. 

oliviasoell_4-1687366717640.png

 

oliviasoell_0-1687366608549.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Matthy79
Super User
Super User

Good to hear it works now.

 

The problem you just posted has nothing to do with the topic. I would suggest you close this topic and create a new one for the other problem including screenshots of the flow and some detail of what you try to achieve.

View solution in original post

16 REPLIES 16
Matthy79
Super User
Super User

Hello @oliviasoell 

 

You should use filter array and put in the expression there. After that you can apply to each to only those items that fit the condition.

 

I also think that your flow is not working because "utcNow()" returns the current timestamp like this "2023-06-21T21:34:42.2115595Z". If you compare it to your expression it will never match. You should only check against the date parts and not the time.

oliviasoell
Frequent Visitor

@Matthy79 I tried adding filter array above it, but something still isn't working right. It is still sending emails to people if the task is complete. I am not really sure what the whole "utcNow()" expressions really mean if I am being completely honest. I am extremely new to Power Automate. Specific pictures or directions would be extremely extremely helpful.

oliviasoell_0-1687441529162.png

oliviasoell_1-1687441562021.png

 

 

Matthy79
Super User
Super User

Your apply to each is not running on the filtered data but on the whole data. You have to apply to each records you filtered.

 

Matthy79_0-1687442203903.png

 

Use this:

Matthy79_1-1687444442891.png

 

oliviasoell_0-1687445846248.png

oliviasoell_1-1687445897740.png

I changed it to the body of the filter array and it the flow is still coming up with an error. @Matthy79 

Matthy79
Super User
Super User

First of all you should do everything in the filter condition so you won't have a condition in the apply to each. What is your formula for you use for addays?

@Matthy79 I think it may help you to know the kind of goal I have set for this flow. I am taking data from an excel sheet that looks like this: 

Screenshot (49).png

I am wanting to send individual email reminders to the specified person 5, 3, and 1 day before the due date of their task. But I don't want the email to send if the task has already been marked as "Complete". I got help from another person on the forum initially which gave me the instructions below on how to filter it to only send 5, 3, and 1 day before the due date of the task, but doesn't include the "Status" filter.  In the screenshot below you can see the formulas that I have included in the condition. Also- thank you SO MUCH for your help and quick replies. I really truly appreciate it. 

 

oliviasoell_0-1687446399999.png

 

Matthy79
Super User
Super User

I can't see the formula in the screenshot (it is to small) but I'm sure there is something wrong about it. But can you provide the output of "list rows present in a table" and I will give you the formula for your for your filter array.

This is the output from the failed test run, I am not sure if this is what you are wanting. I also attached a closer up version of the formulas I have been using, hopefully you are able to see it now. 

oliviasoell_0-1687447434823.png

oliviasoell_1-1687447467622.png

 

Matthy79
Super User
Super User

OK, there are so many things making problems here.

 

1.) It would be much easier if you post sample data as a code (text) to copy. An image is in this case not so helpful.

2.) The data quality in your excel is not good. For example I guess it is possible to write whatever the user wants to write into the status field. If you do a compare of the Status field and the user can type in whatever they want, it is not easy to filter correct. So in your scenario the last entry would also be in the filter because there is a whitespace after Complete ("Complete "). Also if someone types "complete" the filter won't work.

3.) The date coming from excel has a special format. You have to manage that during the compare and of course if you want to calculate.

 

I tried to manage most of the things I saw and here is the result:

 

{"id":"888ccf1c-544c-4447-beae-66e9774ef890","brandColor":"#8C3900","connectionReferences":{"shared_commondataserviceforapps":{"connection":{"id":"/providers/Microsoft.PowerApps/apis/shared_commondataserviceforapps/connections/62947705b1a746319ca1e59aae985afc"}}},"connectorDisplayName":"Control","icon":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDMyIDMyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPg0KIDxwYXRoIGQ9Im0wIDBoMzJ2MzJoLTMyeiIgZmlsbD0iIzhDMzkwMCIvPg0KIDxwYXRoIGQ9Im04IDEwaDE2djEyaC0xNnptMTUgMTF2LTEwaC0xNHYxMHptLTItOHY2aC0xMHYtNnptLTEgNXYtNGgtOHY0eiIgZmlsbD0iI2ZmZiIvPg0KPC9zdmc+DQo=","isTrigger":false,"operationName":"Scope_process_excel","operationDefinition":{"type":"Scope","actions":{"Filter_excel":{"type":"Query","inputs":{"from":"@body('Select_Excel_Output')","where":"@equals(and(not(equals(trim(toLower(item()['Status'])), 'complete')), contains(outputs('Compose_Reminder_Days'), item()['Due Days'])), true)"},"runAfter":{"Compose_Reminder_Days":["Succeeded"]},"metadata":{"operationMetadataId":"0f3c969a-06ab-44f9-9e2e-561622059f49"}},"Select_Excel_Output":{"type":"Select","inputs":{"from":"@outputs('Compose_Sample_Data')","select":{"Task":"@item()['Task_x003a_']","Status":"@item()['Status_x003a_']","Assigned Party":"@item()['Assigned Party_x003a_']","Email":"@item()['Email_x003a_']","Due Date":"@addDays('1899-12-30', int(item()['Due Date']), 'yyyy-MM-dd')","Due Days":"@div(sub(ticks(addDays('1899-12-30', int(item()['Due Date']), 'yyyy-MM-dd')), ticks(take(utcNow(),10))), 864000000000)"}},"runAfter":{},"metadata":{"operationMetadataId":"23fe5f01-d91c-4416-8e02-cbde8b393280"}},"Compose_Reminder_Days":{"type":"Compose","inputs":[1,3,5],"runAfter":{"Select_Excel_Output":["Succeeded"]},"metadata":{"operationMetadataId":"56e34aa1-483b-4a2a-8d10-359dd6002a3b"}},"Parse_Filter":{"type":"ParseJson","inputs":{"content":"@body('Filter_excel')","schema":{"type":"array","items":{"type":"object","properties":{"Task":{"type":"string"},"Status":{"type":"string"},"Assigned Party":{"type":"string"},"Email":{"type":"string"},"Due Date":{"type":"string"},"Due Days":{"type":"integer"}},"required":["Task","Status","Assigned Party","Email","Due Date","Due Days"]}}},"runAfter":{"Filter_excel":["Succeeded"]},"metadata":{"operationMetadataId":"b62fb7f2-17f1-43b7-9e2d-89e763b43ed3"}},"Apply_to_each_filter":{"type":"Foreach","foreach":"@body('Parse_Filter')","actions":{"Compose_Email":{"type":"Compose","inputs":"Send email to \"@{items('Apply_to_each_filter')['Email']}\" for task \"@{items('Apply_to_each_filter')['Task']}\".\n\nDays left: @{items('Apply_to_each_filter')['Due Days']}","runAfter":{},"metadata":{"operationMetadataId":"370bc076-aa5a-4af4-8991-2f927fba2ec8"}}},"runAfter":{"Parse_Filter":["Succeeded"]},"runtimeConfiguration":{"concurrency":{"repetitions":50}},"metadata":{"operationMetadataId":"3868283c-0eb4-4296-9d55-388660435837"}}},"runAfter":{"Compose_Sample_Data":["Succeeded"]},"metadata":{"operationMetadataId":"ffcd8103-8035-4b62-a299-86ca60e4600a"}}}

 

You will have to copy all the data to your clipboard and paste it after "List rows present in a table".

 

Matthy79_0-1687453370247.png

This is how it should look like.

 

I added more steps to make it more readable. Of course you wouldn't even need "Select Excel Output", "Compose Reminder Days" and "Parse Filter" but in my opinion it helps a lot.

 

You have to delete the marked section (From) at the "Select Excel Output" and replace it with the values from "List rows present in a table".

 

In "Compose Reminder Days" you can set the days and new days or change values. If you leave it like this it will filter for 1, 3 and 5 days as wished.

 

I put in a compose action into "apply to each filter" because I don't know what to send. I'm sure you can make it from there. Just use the dynamic content from "Parse Filter".

Matthy79
Super User
Super User

To paste it you will have to add a new step and go to "My clipboard". If you don't see it even if it is in the clipboard press "Ctrl+v".

 

Matthy79_1-1687453829391.png

 

oliviasoell
Frequent Visitor

@Matthy79 This is so awesome, thank you. I didn't even know you could like copy and send workflows like that. I test ran it, the only problem is that it is sending like 6 copies of the email and they are sending to ALL emails listed and not just the one for that row, everything is filtering correctly, but it is sending the same email 6 times to each email. What am I doing wrong?? 😭 I know this must be so painful for you lol. 

oliviasoell_0-1687455491600.png

oliviasoell_1-1687455502725.png

 

 

Matthy79
Super User
Super User

Where is the second apply to each coming from? It was not in the scope. Did you copy it inside the "Apply to each filter" or was it created. You have to delete the second apply to each. Just add a "send an email" action inside the "Apply to each filter" (no other steps needed) and there you create the email. You are not allowed to select dynamic content from the excel or it will create another apply to each. If you don't find all the needed values in the parse JSON, you will have to add them in the select statement (Just give it a name on the left side and put in the dynamic value from the excel on the right side) and of course in the schema from "parse JSON" (you can also use "Generate from sample" from a test-run after you changed the select statement.

I just need to add the property name from the property name column into it. I am not sure how to change the Parse filter accordingly, and I am scared I will mess it up as it is FINALLY working the way I want it to. All of the other values are perfect. I added Property Name and the dynamic content to the "Select Excel Output" but am not sure what to do after that with the parse JSON. 

Matthy79
Super User
Super User

1.) Let the flow run once (skip that if it already run after you changed the select card)

2.) Go to the last flow run history

3.) Copy the output of the select card into the clipboard

4.) Edit the flow and navigate to parse json

5.) Click on “Generate from sample”

6.) Insert from Clipboard and confirm

7.) Use the new available dynamic content in the mail action

8.) Save the flow and pray that everything works out

 

If it doesn’t work I will change it tomorrow.

What you suggested worked (YAY!), however, I have since switched from sending emails to sending messages via teams (which isn't a big deal, and WAS working prior to me changing the parse json) but now my test flows keep failing and saying this: 

{
  "error": {
    "code": "GraphUserDetailNotFound",
    "message": "No user details with email or UPN 'user@domain.nl' were found in Graph."
  }
}

but like obviously with my real email information.  

Matthy79
Super User
Super User

Good to hear it works now.

 

The problem you just posted has nothing to do with the topic. I would suggest you close this topic and create a new one for the other problem including screenshots of the flow and some detail of what you try to achieve.

Helpful resources

Announcements

Celebrating the May Super User of the Month: Laurens Martens

  @LaurensM  is an exceptional contributor to the Power Platform Community. Super Users like Laurens inspire others through their example, encouragement, and active participation. We are excited to celebrated Laurens as our Super User of the Month for May 2024.   Consistent Engagement:  He consistently engages with the community by answering forum questions, sharing insights, and providing solutions. Laurens dedication helps other users find answers and overcome challenges.   Community Expertise: As a Super User, Laurens plays a crucial role in maintaining a knowledge sharing environment. Always ensuring a positive experience for everyone.   Leadership: He shares valuable insights on community growth, engagement, and future trends. Their contributions help shape the Power Platform Community.   Congratulations, Laurens Martens, for your outstanding work! Keep inspiring others and making a difference in the community!   Keep up the fantastic work!        

Check out the Copilot Studio Cookbook today!

We are excited to announce our new Copilot Cookbook Gallery in the Copilot Studio Community. We can't wait for you to share your expertise and your experience!    Join us for an amazing opportunity where you'll be one of the first to contribute to the Copilot Cookbook—your ultimate guide to mastering Microsoft Copilot. Whether you're seeking inspiration or grappling with a challenge while crafting apps, you probably already know that Copilot Cookbook is your reliable assistant, offering a wealth of tips and tricks at your fingertips--and we want you to add your expertise. What can you "cook" up?   Click this link to get started: https://aka.ms/CS_Copilot_Cookbook_Gallery   Don't miss out on this exclusive opportunity to be one of the first in the Community to share your app creation journey with Copilot. We'll be announcing a Cookbook Challenge very soon and want to make sure you one of the first "cooks" in the kitchen.   Don't miss your moment--start submitting in the Copilot Cookbook Gallery today!     Thank you,  Engagement Team

Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!    

Welcome to the Power Automate Community

You are now a part of a fast-growing vibrant group of peers and industry experts who are here to network, share knowledge, and even have a little fun.   Now that you are a member, you can enjoy the following resources:   Welcome to the Community   News & Announcements: The is your place to get all the latest news around community events and announcements. This is where we share with the community what is going on and how to participate.  Be sure to subscribe to this board and not miss an announcement.   Get Help with Power Automate Forums: If you're looking for support with any part of Power Automate, our forums are the place to go. From General Power Automate forums to Using Connectors, Building Flows and Using Flows.  You will find thousands of technical professionals, and Super Users with years of experience who are ready and eager to answer your questions. You now have the ability to post, reply and give "kudos" on the Power Automate community forums. Make sure you conduct a quick search before creating a new post because your question may have already been asked and answered. Galleries: The galleries are full of content and can assist you with information on creating a flow in our Webinars and Video Gallery, and the ability to share the flows you have created in the Power Automate Cookbook.  Stay connected with the Community Connections & How-To Videos from the Microsoft Community Team. Check out the awesome content being shared there today.   Power Automate Community Blog: Over the years, more than 700 Power Automate Community Blog articles have been written and published by our thriving community. Our community members have learned some excellent tips and have keen insights on the future of process automation. In the Power Automate Community Blog, you can read the latest Power Automate-related posts from our community blog authors around the world. Let us know if you'd like to become an author and contribute your own writing — everything Power Automate-related is welcome.   Community Support: Check out and learn more about Using the Community for tips & tricks. Let us know in the Community Feedback  board if you have any questions or comments about your community experience. Again, we are so excited to welcome you to the Microsoft Power Automate community family. Whether you are brand new to the world of process automation or you are a seasoned Power Automate veteran - our goal is to shape the community to be your 'go to' for support, networking, education, inspiration and encouragement as we enjoy this adventure together.     Power Automate Community Team

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

Tuesday Tip | How to Report Spam in Our Community

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   Today's Tip: How to Report Spam in Our Community We strive to maintain a professional and helpful community, and part of that effort involves keeping our platform free of spam. If you encounter a post that you believe is spam, please follow these steps to report it: Locate the Post: Find the post in question within the community.Kebab Menu: Click on the "Kebab" menu | 3 Dots, on the top right of the post.Report Inappropriate Content: Select "Report Inappropriate Content" from the menu.Submit Report: Fill out any necessary details on the form and submit your report.   Our community team will review the report and take appropriate action to ensure our community remains a valuable resource for everyone.   Thank you for helping us keep the community clean and useful!

Users online (3,613)