For each row in column “Status” if any fail find , send email 1 or email 2 if all pass. Can you please help me with the expression in for each to send mail on conditional basis…

for each row in column D3:D26 column name “Status” - if any fail find , send email 1 or email 2 if all pass.
Can you please help me with the expression in for each to send mail on conditional basis…

Hi @r0818 ,

For each row in datatable activity is not required, you can remove that.

Instead you can use filter datatable activity, with condition Status = “fail”.

then If activity with following condition:

dt_Filtered.rows.count > 0

( where dt_Filtered is output of Filter datatable activity and dt_Filtered.rows.count gives total rows with failed status)

Then : Send failed mail

Else : Success mail

Hope it helps.

HI,

Hope the following sample helps you.

Sample with ForEachRow

Sample without loop and if

Please also check the following sample (Main.xaml and Sequence.xaml)

failExists = dt.AsEnumerable.Any(Function(r) r("Status").ToString="fail")

Sample20230410-1L.zip (12.1 KB)

Regards,

1 Like

@r0818

You need mot use a for loop…instead whatever if condition you are using inside the for loop should be used directly with the following expression

Dt.AsEnumerable.Any(function(x) x("Status").ToString.Equals("Pass"))

On the then side send pass email and on else side send fail email

Hope this helps

Cheers

1 Like

Hi @r0818

Sure, I can help you with that! Here’s an example workflow that you can modify to fit your needs:

  1. Drag and drop a “For Each Row” activity onto your workflow canvas.
  2. In the “For Each Row” activity, set the “Type Argument” to “DataRow” and the “Values” to your range of cells containing the data you want to loop through (in this case, D3:D26).
  3. Inside the “For Each Row” activity, add an “If” activity to check the value of the “Status” column for the current row. You can do this using the following condition:

row("Status").ToString.Contains("fail")

This condition will check whether the value in the “Status” column for the current row contains the word “fail”. If it does, the condition will be true and you can send an email. If it doesn’t, the condition will be false and you can continue looping through the rows.

  1. If the condition in the “If” activity is true, use the “Send Outlook Mail Message” activity to send an email to the appropriate recipient. You can set the “To” field to “email1@example.com” if any row fails, and “email2@example.com” if all rows pass.
  2. If the condition in the “If” activity is false, you can continue looping through the rows without sending an email.
1 Like

will it check for each row in that column?

Thank you , I will try this

Thank you so much
I will check

1 Like

@r0818

Yes please try it

cheers

Hi @r0818 ,

For more info on this, screenshots are attached.

Filter datatable configuration:

Use filter datatable activity, with condition Status = “fail”.

then If activity with following condition:

dt_Filtered.rows.count > 0

( where dt_Filtered is output of Filter datatable activity and dt_Filtered.rows.count gives total rows with failed status)

Then : Send failed mail

Else : Send success mail

Hope it helps.

Thank you, can you please guide me using filter datatable, is there any expression to change the color font color of FAIL as red and pass as Green into excel sheet andthen attaching xls to mail?

Hi I tried but with this expression
dt_sendMail.AsEnumerable.Any(Function(x) x(“ActivityStatus”).ToString.Contains(“PASS”)) is true and tried with FAIL as well, always its going to else block and getting ERRRs email message.

Can you please help?

Always

@r0818

Did you add all the column values as fail…what this checks is if atleast one is pass

If you need to check if atleast one is fail instead of pass use fail

Also try using like this…may be casing is different

x("ActivityStatus").ToString.ToUpper.Contains("PASS") - this will convert data into upper case and check

Hope this helps

cheers

I ran with "Success " and all rows are status o fSuccess… but still its going to then block and sending Error found email. logic should be if atleast one error on status column then email as errors found. If all pass/success then all passed success message should supposed to trigger. But its not working …

image

@r0818

If all are success and if you give success in the expression it would ideally go to true

image

cheers

then it should trigger success mail rt from Then part?

@r0818

If you want to check if atleast once success is there in the column then use the formula with success in the text in and then use send email in then side

if you want to check for atleast one failed then use failed in the text and then use send email for error or failed in the then side

Hope this is clear

cheers