Using a for each loop and a break activity

Hi all

I have an email address in a mail message and in a datatable I have a list of ‘safe sender email addresses’. I need to loop through this datatable and if one of the email addresses matches the email address in mail message I need to break the for each loop. If at the end of looping through the whole data table, the email from the mail message isn’t found, then I need to create a business exception.

I can’t quite figure out the logic to do this. I guess I use a for each activity for each row in the datatable and then an IF statement in the for each loop with does the row contain the email address from the mail message. If it does then go to a ‘Break’ - I don’t know how to raise a business exception if loops through the whole data table and doesn’t find the email address?

Or any other way that you can think of that may be better?

Thanks
Jordan

You can use A variable say IsExp=“True”
In if statement where u are using break use IsExp=“False”
That means only when u find that word u will change flag to false
After for each if IsExp=“True”
Then Throw Exception activity in that choose Business Exception

2 Likes

@jordrowley

For raising business expection you can place a if statement after the for each row and check whether the email address variable holds the values or not

place the If condition to check the value

Example flow

Mark as solution if this helps

Thanks

1 Like

@jordrowley,

I would actually recomend using Select instead of looping through the whole table. Something like this:

DataTableMails.Select("[ColumnMails]=’"+varMailSearch"’") --> this will return a collection of rows in the datatable where the the mail in the datatable matches the mail that you are searching for.

You can count the number of elements return: DataTableMails.Select("[ColumnMails]=’"+varMailSearch+"’").Count --> if this value is 0, then your mail is not on the datatable and you can throw your error. No need for a loop!

2 Likes

@ImPratham45 @ksrinu070184 @RockSolid hi all - they all make sense; thank you for replying. I’m going to try them now and then mark the solution as complete when I’ve done. Really good to get 3 different ways to solve as I can learn from all of them

Thanks :slight_smile:
Jordan

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.