If string variable is blank ("") then do something else (via If activity)

Hi

I am new to UiPath :slight_smile:

I have two string variables with email or phone information - converted form regex. (FYI If the field is blank I am getting a “” (nothing) result - as expected). I am having trouble with two scenarios, please see below.

My Variables names:
VarEmailString
VarPhoneString

My scenario: I need to complete two fields differently when the variables are blank. I will be using the If activity to complete the follow up actions. Photos are attached with my attempted solutions.

Problem #1 / Field 1:
If VarPhoneString or VarEmailString is not blank then click Reply to Customer.
Else if both are blank then click FYI only.
image

Problem #2 / Field 2:
If VarEmailString is blank - then go to nested If statement that says: If VarPhoneString is blank - then select return via email.
Else - if both are blank then select N/A.
image

It’s probably a simple solution but I am having some trouble, so any assistance with a VB expression solution would be appreciated :slight_smile:

Kind regards

Steve

@Steven_McKeering Use regex to get email and phone number

Hello

I did in the first place yes.

However my problem is changing the actions when the result is blank.

Thanks

@Steven_McKeering,

You can check your string is Empty with
String.IsNullorEmpty(VarEmailString)

It will return you a Boolean value. You can use it in the if condition.

TanQ,
Michael Udhaya

2 Likes

Hi @Steven_McKeering!

when you are using regex the output is list of matches, so first you must go through that list and check if you pattern is ok,put some condition for validation in loop and if that condition returs true assign that item to variable. After that loop you can use if statement and in contdition you can write String.IsNullorEmpty(VarEmailString) as @Michael_Udhaya wrote to control your flow.

Cheers!

Hey @Michael_Udhaya

Thank you

I will give this a try.

Hi @Michael_Udhaya @Nikola_Drazic

I can’t get it to work.

Like this?
image

Or Like this?

image

Kind regards

Steve

Hi @Michael_Udhaya @Nikola_Drazic

Thank you for your help :smiley:

The ‘IsNullorEmpty’ string options did not work for me in this instance.

I did discover that ‘IsNullorWhitespace’ was the solution.

Problem 1’s solution:
Put the below expression in the VB expression of the If activity (see below images):
“string.IsNullOrWhiteSpace(VarEmailString) and string.IsNullOrWhiteSpace(VarPhoneString)”
image
Simply put - If both phone and email variables are blank/whitespace THEN click ‘fyi’ ELSE Click ‘reply direct’
image

Problem 2’s solution:
I solved this in two steps.

  1. Determine if Phone variables and Email variables are blank
    IF both email and phone variables are blank THEN type n/a (like problem 1) ELSE see step 2
  2. Determine whether to type in Phone variable or Email variable
    Insert another If activity and check if phone variable is blank using same VB expression in step 1(string.IsNullOrWhiteSpace(VarPhoneString) THEN type Email option ELSE type in Phone option (fyi only - phone is business preference)

(see below images):
Step 1 full expression
image
Step 1 (Blue) and Step 2 (Purple)

Thanks everyone for their assistance :slight_smile:

Kind regards

Steve

1 Like

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