Use Try Catch to consolidate messages to be sent at the end

Hi all,

I have to check rows of Quantity, Weight, Total Money of dt1 & dt2
Currently compare row by row of Q,W,T dt1vsdt2 if not equal will stop and send an email. I use try catch and exception email.

But I want: to check all to the last row and consolidate messages to be sent at the end (stop at the end)

Hi @anh.nguyen

Try this way. It might help you.

  1. Initialize Variables

    • discrepancyMessage (String)
    • emailContent (String)
  2. Read Data Tables

    • Read Range (dt1)
    • Read Range (dt2)
  3. For Each Row (row1 in dt1, row2 in dt2)
    4. Compare Values

    • If row1(“Quantity”) <> row2(“Quantity”) OrElse
      row1(“Weight”) <> row2(“Weight”) OrElse
      row1(“TotalMoney”) <> row2(“TotalMoney”)
      • Append to discrepancyMessage
    1. Continue
  4. Check Discrepancies

    • If discrepancyMessage is not empty
      7. Prepare Email Content
      • Assign emailContent = “Discrepancies found:” + Environment.NewLine + discrepancyMessage
      • Else
        • Assign emailContent = “No discrepancies found.”
  5. Send Email

    • Send Outlook Mail Message
      • To: Your email address
      • Subject: “Discrepancy Report”
      • Body: emailContent

Hope it helps!!

1 Like

Hey @anh.nguyen ,
Can you give a try of below sequence
Initialize Variables:

  • consolidatedMessage (String) = “”

For Each Row (row in dt1):
If row(“Quantity”) <> dt2.Rows(rowIndex)(“Quantity”) Or
row(“Weight”) <> dt2.Rows(rowIndex)(“Weight”) Or
row(“Total Money”) <> dt2.Rows(rowIndex)(“Total Money”):

  Add to consolidatedMessage:
  - Append line with discrepancy information to consolidatedMessage

After Loop (outside For Each Row):
If consolidatedMessage is not empty:
Send Email:
- Recipient: Your Email
- Subject: “Consolidated Discrepancies Report”
- Body: consolidatedMessage

1 Like

Hi @anh.nguyen ,
You can use
for loop and if else condition

1 Like

I use Append Line?

Up, please help me. thanks