Multiple Conditions in If Statement

Hello,

Building automation for mailing purposes and stumbled upon one logical issue, which is “How can I programmatically make a script that would be able to act upon multiple IF conditions?”

I’ve got A, B, C, D types of recipients of my email and now I need to come up with an email accordingly.

Looks like the original If-Statement Activity is helpful in case when true or false answer can be given only. What should I do when:

if the recipient is A - send 1
if the recipient is B - send 2
if the recipient is C - send 3

Thank you, your expertise is much appreciated

Hey @ykuzin,

Try using a Switch activity. You can specifiy conditions for multiple conditions.

2 Likes

@ykuzin

Check as below

Hope this helps

Thanks

1 Like

Hi,

As another solution, I recommend to use Dictionary.

For example, if we set dictionary variable as the following in advance.

dictMessage("A@example.com")="Message for A"
dictMessage("B@example.com")="Message for B"
dictMessage("C@example.com")="Message for C"

Then we can send it as the following without IF activity

img20200921-1

Regards,

1 Like

Thank you, I would like to try your approach let me just put a little bit more context into my scenario first, to see if it is applicable here.

We’ve got a data table, where one of its columns stores email addresses and another one stores labels, let say label1, label2, label3. So eventually we have got something like that:

email _________ label
one@mail.com ____ label1
2@mail.com ____ label2
another@mail.com ____ label3

Apparently we have looped through this table using for each row and now we’d like to start sending emails, where if it comes to label1, please, send it to one@mail.com and so on respectively. As you may guess, addresses might be changing dynamically, but those labels are constant.

Now, my question is…how to update emails in that dictionary having a data table as a place where normally they are being stored?

Thank you very much for your input

Hi,

Thank you for sharing your scenario.
If my understanding is right, we need to prepare dictionary for label and message like…

dictMessage("label1")="Message for label1"
dictMessage("label2")="Message for label2"
dictMessage("label3")="Message for label3"

Then we can write it as the following.

img20200921-2

If there is misunderstanding, please let me know.

Regards,

2 Likes

@Yoichi
Not a single drop of misunderstanding here, thank you!

Following your advice, I have tried to declare a dictionary variable first that now looks like this:

EmailDictionary (System.Dictionary<.String> ,<.String>)= {{“label1”,“Message for lavel1”,
{“label2”,“Message for label2”}
}

Actually, since it’s got an error the variable won’t be declared and now I need to figure out why. It seems to me that the problem is with syntax. Looking onto your example I would like to understand what is the proper way to declare a dictionary variable.

Going forward, if I understand correctly “Message for lavel1” is a message’s body content, can some graphics like .jpg be embedded in here?

Thank you in advance!

Hi,

Hope the following helps you.

Sample for Initialize Dictionary (VB.net)

Sequence.xaml (6.9 KB)

How to add image to email

Regards,

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