Nested If Condition replacement?

I made a workflow that consists of nested if condition, I want a replacement for that any suggestions are welcome. if possible provide a xaml file for better understanding. I’m attaching the screenshot.snap2

Personally I’ve found that nesting Switches with the Boolean type often improve readability, I don’t use the if statements at all anymore at this point… However, if the process is really too large, you’re probably better off flow charting it using flow decisions/flow switches.

A single if is usually fine, but as soon as you begin nesting, UiPath is built to push you towards flowcharts, however if you need to nest 1-2 if’s, Switches are pretty good for it so long as you’re not cramming entire processes within the switch cases.

1 Like

thanks for your suggestion.
but here the problem is i can not use any nested if/switch.
i tried to go with the flow decision but in my condition it’s not sutable.

i’m explaining my condition.

there is a variable that contains 30 mails.
the nested if condition are in a FOR EACH activity.
in FIRST NESTED IF: i tried to figure out a specific email subject.
in SECOND NESTED IF: i tried to figure out specific mail body.
if both condition satisfied then i proceed to the next sequence.

Your conditions can use things like AND, OR and so on… you dont need to nest them if you dont need to :slight_smile:


@bcorrea is correct that and/or statements in your conditional would be best here. You don’t need to nest anything if you just want to make sure both conditions are true.

This should work fine in a single If statement:
Subject.ToString.Contains(in_Config("MailSubject").ToString) And Body.ToString.Contains(in_Config("MailBodyKeyWord").ToString)


when i combined the condition the execution goes to the else part.

When running in debug mode can you check and verify that the io_MailSubject actually contains the MailSubject element stored in your Config and the same for the Mail.Body containing the MailBodyKey value?

You should be able to inspect the variables when running in debug mode, or prior to the if you could also log them to manually inspect them in the output panel…

I’m inclined to think there is an issue with a variable type, the passing of the arguments, or your config since the if condition line looks correct from what I can tell.

Note: If casing doesn’t matter you can also add a .ToLower into the if conditions just to further proof the process: io_MailSubject.ToString.ToLower.Contains(in_Config("MailSubject").ToString.ToLower) and Mail.Body.ToString.ToLower.Contains(in_Config("MailBodyKey").ToString.ToLower)

1 Like

I’ve checked it. All variables and arguments are correct. When i use NESTED IF it works Fine but when i Combine the two conditions using “and” operator it did not work. I also tried two separate IF conditions but that also failed.

i noticed you are using variables that come from different sources to check the Body and the Subject of your emails, did you check those to see if they are ok? io_MailSubject and Mail.Body

1 Like

@bcorrea they are fine.