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

Flow with multiple conditions to send an email

I have a flow that is pulling data from Power Bi via a query then creating a HTML table to send an email.  However, I have a condition to check if the HTML table is empty so an email will not be triggered.  I need a second condition to to check a field, "Action" for a specific value (no action, supervisor, and manager) to trigger the email base on that value.  Example, no action it goes to one address, supervisor goes to another address, and manager goes to another email address.  I thought I could use a switch but I don't know the expression to use to filter by the field, "Action" to add the switch.

 

I am very new to creating flows and this one has me stumped.  

2023-09-19 08_41_18-Window.png

 

2023-09-19 08_42_28-Window.png

 

15 REPLIES 15

@KONeill102399 The Select action returns an array of items. You should use the length() function to check how many items are returned. If there are no results, a zero would be returned. How many items are returned in the Select action—if there is more than one item, the switch action may not work in this case (at least not from where it is currently placed in your flow).

 

Can you show the output of the HTML table? 

 

There is one column, "Action" that needs to be checked but return (3) different paths.  Here is the output from the HTML table.  I want to check the column, "Action" to escalate the issue base on the value.2023-09-19 09_21_29-WMI PGI Failure Report - 09_19_2023 - Message (HTML).png

@KONeill102399 The logic of your flow might need to be adjusted. Currently you are creating the HTML table first then running the check. 

 

Is the intention to send the entire HTML table to a specific email address or only to send a specific row of data to a specific address?

I want to send the entire HTML table in the email not the specific rows with the data.  

@KONeill102399 I'm still a bit unclear on how you plan to evaluate the Action column. In the screenshot you sent there are 4 rows of data. Is it assumed that each row has the same action in this case? Or could each row have different actions? Could you clarify?

 

Hi, @KONeill102399 , couple of things that I think that you might need:

  1. Make A 'uniqueActionsArrVAR' Array Variable - I am pretty sure that you'll need to build an array of values from that 'Actions' column, then run an apply to each on a union() of that array
  2. Remove 'Format Table Headers' Action - I'm making an assumption here, but the 'Select Data from Query' action is going to enable you to set your headers, then you can use the 'Create HTML Table' on auto afterwards. (or just go straight to the table!)

The need for the first is because you cannot be sure that all the actions will be the same, so your Switch action would not be run appropriately, as it would not have direct data to feed off of. Once you are inside that unique array, though, you can just place 'Current item' in the Switch 'On' field.

 

I think this is why @creativeopinion was wondering why there wasn't any flow actions around handling those Actions from from BI data.

 

How To Iterate Over The Actions

All of this is hopefully not too strenuous to achieve ... I have edited in here some steps to ensure that you are not making 3 email actions:

  1. Initialize two new variables before all your other actions:
    1. Array - Named 'uniqueActionsArrVAR'
    2. String - Named 'emailRecipientsVAR'
       
  2. After the Power BI action make a separate Select action (don't delete your current one) and rename it 'Select uniqueActions'
    • In the 'From' field use the same value as you did in the other
    • In the 'Map' field you might need to get a bit creative, but hopefully you can just select the column

      That will result in a string array, that should look something like the example below these steps
       
  3. After the Select action create a Set variable action to set the 'uniqueActionsArrVAR' value then within that:
    1. ... in the 'Value' field of this action open the expression builder instead of using dynamic data
    2. ... add the union() function
    3. ... inside the union function add the output of 'Select uniqueActions' twice, comma separated

      Each time this runs you will now have a definable list of whether any actions are needed
       
  4. Now add an Apply to each action after all the other important actions in the flow (the ones you've shown us):
    1. In the 'Select an output from previous steps' field of the Apply to each select 'uniqueActionsArrVAR' from the Dynamic data
    2. As the first step create a Switch action and in the 'On' field select 'Current item' from the Dynamic data and make your 3 cases:
      1. supervisor
      2. manager
      3. no action
    3. After the switch add your email action and in the 'To' field pick the 'emailRecipientsVAR' from the Dynamic data and fill out the email with all the data

 

Select Output Examples

The output from the Select Action in #3 might look like this:

[
  "supervisor",
  "manager",
  "no action"
]

 

Or it might look like this:

[
  "supervisor",
  "no action"
]

It will all depend on what actions are listed in the BI data.

 

Moving Forward

Now you have your Switch and it will run on whichever values you choose in the cases, with whichever actions that you wish to have taken within them for each!

 

Additionally, if you wanted to be super clever, much of this could be done in parrallel to your other actions, then run your Apply to each action after everything. This would assist with making the flow more efficient. 🙂

 

If you wished to personalise the body of the email for supervisor/manager/no action, then either move the email action back into the Switch, or make an email body variable to edit there.

 

When making new actions it's good to get into the habit of giving them unique names, too. To make it easy for myself on things like initializing variables I simply copy the variable name and paste it in instead of the word 'variable' in the renaming.

Each row might have a different action but I want the entire table to be sent each time.

Yes, it will. 🙂

 

(apologies, assumed that was responding to me, just seen the reply part)

 

So, with what I'm suggesting, let's say that example array is the output of the union() that I spoke of.

 

Well, the output from the Select I suggested might have been:

 

[
  "supervisor",
  "no action",
  "no action",
  "manager",
  "no action",
  "manager",
  "manager",
  "no action"
]

 

The union() will remove all the duplicates. So it will only send as many emails as there are different types of actions. However you would still use the output from your original create html table in the emails that you send. 🙂

 

If you wanted to be even cleverer with the Switch, then you could have a single email action after it inside the apply to each, then in the switch just update an emailRecipientsVAR string variable and place that in your email 'To' field!

 

(imma update my steps with that, I think ... and make the array more contextually apt)

Wow!  That is a lot of information.  I will have to try this later today.  I did convert the data to an array, filter by the column, and created an apply to each to read the data.  But I wasn't sure where this should have happen in conjunction with the condition and formatting the table.  The, Format Table Headers' Action is so I can add spaces in the headers so it is easier to read for the user.  

 

I am really new to power automate so this is extremely helpful.  I will try this.  

No wuckas, @KONeill102399 ... take your time ... and most of all ... try some sh ... stuff out!

 

If you want to protect yourself you can always place strategic 'Terminate' actions, and or use fake data. Or, in your case use your own email address for each Switch case.

 

Oh, and sorry for the wall of text.

 

Times gone by I would map it all out for you with a flow and suchlike, but I'm literally working on this stuff now, so it's hard to push around all that ... resource-wise. 🙂

I got everything to work except the Apply to each.  I received this error message:

The execution of template action 'Switch' failed: The result of the evaluation of 'scope' action expression '@items('Apply_to_each')' is not valid. It is of type 'Object' but is expected to be a value of type 'String, Integer'.

 

I am not sure what this means.

 

Can you maybe show a screenshot?

 

I suspect it is in the Map section of the Select action.

 

Make sure that you have ONLY the selected field in there. You may need to press the little 'T' button to the right to do this.

 

It should look something like this:

something like this.png

 

That is #3.  I thought that what I did was wrong too because the header of the array displayed in the output.  Here are my screen shots.

2023-09-21 07_38_43-Edit your flow _ Power Automate.pngRun-History-Power-Automate.pngEdit-your-flow-Power-Automate.png

@KONeill102399 I believe I now have a better understanding of your requirements.

 

In your particular case, the Switch action will not work. Reason being is that you are looking at the Action column values as a whole (not individual). For this reason you will need to extract those values and combine them together. 

 

I don't actually use Power BI in my daily workflow. However, I was able to come up with a solution that I think will work.

Count Data Returned from Power BI

After the Run a query against a dataset action, add a Compose action. 

 

Use the length() function to count the First table rows. You indicated in your original post that you wanted to check if the HTML table was empty. I think it would make more sense to check if there is any data returned (if not, then don't bother continuing on with the flow).

 

creativeopinion_0-1695311977915.png

 

Add Condition

Add a Condition action. Insert the outputs from the Compose action above. If the length returned is not equal to 0 (this means there is data).

 

Insert all your actions in the YES branch. 

creativeopinion_1-1695311993976.png

 

Here is where you can add your HTML table actions. 

 

creativeopinion_9-1695312886707.png

 

Select the Actions

For my example, I'm using a column named Status. In the outputs of the Run a query against a dataset action the key for the Status column is "MyTable[Status]" which I'll use in the Select action.

 

creativeopinion_4-1695312552560.png

In the Select action, insert the First table rows dynamic content into the From field. Click on the icon to the right of the Map field to switch from Map to Key value mode. 

 

creativeopinion_10-1695313193104.png

Insert an expression into the Map field. You'll need to use the item() function, add a question mark, square brackets and single quotes (shown below).

item()?['']

In between the single quotes, enter the key of your column. The key is the red text between the double quotes. In my case, my key is: MyTable[Status]

My expression is:

item()?['MyTable[Status]']

creativeopinion_3-1695312530221.png

 

Run a test! Check the outputs of your select action. It should return ALL values from the Action column, in my case the Status column. Keep in mind, the output of the Select action is an array of values.

 

creativeopinion_2-1695312516236.png

 

Unique List

This next step is optional. You can use the union() function to create a unique list of values (removing all duplicate values). 

 

Insert an expression with the union() function. The union() function takes two arrays. You can insert the outputs from the select action.

union([array 1], [array 2])

creativeopinion_6-1695312653294.png

 

Join List (array to string)

Next, add a Join action to convert the array to a string. Insert the outputs from the Compose action above (with unique values) into the From field.

 

In the Join with field, enter a comma (or semi-colon.. any separator) and a space. 

creativeopinion_11-1695313691693.png

 

Run a test. View the outputs. You can see the input is an array, the output is a string of text separated by a comma.

 

creativeopinion_7-1695312736817.png

 

Condition Check

The reason that the Switch action will not work in your case is that you have multiple values you are looking at. Instead, you need to run a Condition check to see if the outputs contain the value(s) you are looking for. 

 

Add a condition action. In the first value field insert the outputs from the Join action. Change the operator to contains. Since this is a string of text you are checking against, you want to check if it contains the value you'll be entering into the second value field.

 

In the second value field, insert the text you'd like to search for. Keep in mind this text is case sensitive

creativeopinion_8-1695312752507.png

 

Send an Email

Add a send an email action to the YES branch. Insert the appropriate recipients and content. 

creativeopinion_16-1695314466417.png

 

Repeat for Each Action Type

For each Action type, you'll need to create a condition. You can run these parallel to each other since you've indicated that items may have different conditions. Either way you will need to send an email to specific recipients depending on the action type. 

creativeopinion_17-1695314571313.png

 

 

Hope this helps!


If I helped you solve your problem—please mark my post as a solution .
Consider giving me a 👍 if you liked my response!

👉 Watch my tutorials on YouTube
👉 Tips and Tricks on TikTok

 

 

 

 

 

Hey, @KONeill102399 , all you should need to change is to make this:

 

not good.png

 

Look like this:

good.png

 Then you will have a string array. 🙂

If you are wondering how to change the view, just tap the button on the side I've shown it with the tool tip, here:

common - switch to text mode.png

 

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (628)