Hi,
I want to add below 3 conditions, which activity should be used?
1. If email contains ‘abc’, do this set of action
2. If email contains ‘xyz’, do this set of action
3. Else log a message, ‘no email found’
Hi,
I want to add below 3 conditions, which activity should be used?
1. If email contains ‘abc’, do this set of action
2. If email contains ‘xyz’, do this set of action
3. Else log a message, ‘no email found’
You can use the Else If activity, by using this activity you can check the multiple conditions.
Check the below image for better understanding,
Hope it helps!!
@mkankatala, will both conditions execute if both abc and xyz emails are present?
In the same mail both abc and xyz has to be present. If it is the condition, then check the below,
- Condition -> Mail.Contains("abc") AndAlso Mail.Contains("xyz")
Hope you understand!!
My requirement is like,
the bot will run once a day
it will extract emails having subject abc and also extract emails having subject xyz
for both subjects, there will be different set of actions
will else if be used in that case?
Then I have already given the same logic in above response… @shilpashree.mohanty
Check the below workflow for better understanding,
Hope you understand!!
Give it a try on what @mkankatala explained.
You have one another option as well for this kind of situation that is Switch case.
Activities - Switch (uipath.com)
Thanks,
Ashok
@shilpashree.mohanty I hope it solve your issue.
This is the best possible sotest code.
string actionMessage = email.Contains("abc")
? "Email contains 'abc'"
: (email.Contains("xyz") ? "Email contains 'xyz'" : "No email found containing 'abc' or 'xyz'");
Other Common use by Developer
if (email.Contains("abc"))
{
**// Do actions for email containing 'abc'**
Console.WriteLine("Email contains 'abc'");
}
else if (email.Contains("xyz"))
{
// Do actions for email containing 'xyz'
Console.WriteLine("Email contains 'xyz'");
}
else
{
// Log message for no matching email content
Console.WriteLine("No email found containing 'abc' or 'xyz'");
}
string email
: This variable stores the email address you want to check. Replace your_email_here
with the actual email string.if (email.Contains("abc"))
: The if
statement checks if the email
string contains the substring "abc"
using the Contains
method.if
statement executes, performing actions specific to emails containing "abc"
(here, we’re just printing a message using Console.WriteLine
).else if (email.Contains("xyz"))
: If the first condition (email.Contains("abc")
) is false, the else if
block checks if the email
string contains "xyz"
using Contains
.else if
block executes, performing actions for emails containing "xyz"
(again, printing a message here).else
: If neither of the previous conditions is true, the else
block executes. This typically represents a case where the email doesn’t contain "abc"
or "xyz"
.you can use else if activity for this .
If more conditions switch activity would be better option.