IF statement Then or Else

In my process I have to search a place, once I search the place a separate screen appears to enter a name. IF that name already exist a message above the ‘Type Into’ textbox will appear saying “Name already exists”, if the name does not exist it will continue with the process.

I have a Get Text for “Name already exists” output value = strError

For my IF statement I’ve used:

  • strError.Contains(“Name already exists”)
  • strError.Contains(“already”)
  • strError.Equals(“Name already exists”)

When the process is either true or false it always completes the ‘Else’ set of processes and never the ‘Then’. Any ideas as to why?

Hi ,

Is there any symbol in the message which you have get from screen? (you can test by debugging it or printing it to see in output panel.)

IF statement which provide in topic - do you use all of provided statement with AND or OR operation or just a single one for each testing ?

Please attached screenshot for more investigation.

There’s no symbol to use.

They are all single lines that I’ve tested with, neither fully work.

Hi @shdacak

after reading the string use trim and convert to lower and do comparison.

1 Like

Hi @sunilch

for which string or does it not matter?

1 Like

Hey @shdacak,

Try this please strError.ToLower.Contains(“name already exists”)

Also please check you have passed your strError variable in Get Text activity’s output property.

Thanks :slight_smile:


does having N as n for ‘Name’ make a difference? just curious.

1 Like

Yep @shdacak,

You need to either use exact name or convert it to upper/lower case.

Is it resolved now ?

Thanks :slight_smile:

Still not resolved. If I leave it as strError.ToLower.Contains(“name already exists”) it only processes Else and if I do Not strError.ToLower.Contains(“name already exists”) it only processes Then.

1 Like

@shdacak, Can you please share xaml,

Also try printing strError in log before if.

Thanks :slight_smile:

I can’t share the XAML.

When I print it shows as "
Name already exists"

Do you think the spaces make a difference?

1 Like

@shdacak… Yes…it does make the difference. Try .trim to see if its removing the spaces.

I did this and then I started to receive this error:
If: Object reference not set to an instance of an object.

@shdacak…pls share the screenshot of your workflow.

Looks like you are trying to trim a null value. You get the object reference error when you try to trim a string which is actually null value.


Above the message box is the “Get Text” activity

@shdacak - Since you already mentioned it is printing like this…

You can remove the new line by below two methods…1. Regex 2. String.Split



if you wish you use Regex then :
Assign StrOutput = System.Text.RegularExpressions.Regex.Match(StrError,"(?<=\n).*").Value

if you wish you use String.Split then :
Strsplit = String.Join(Environment.NewLine,StrError.Split({Environment.NewLine},StringSplitOptions.RemoveEmptyEntries))

My Input Text :slight_smile:

Hope this helps.

Hi @shdacak

Sorry for the delayed response. I understood the issue. The problem is

  1. your input string contains New line
  2. your input string doesn’t contains a value all the time ie., you will get null value.

If you use trim function it will throw error when you get null value, if you dont use trim then comparison fails. My suggestion follow the below steps and try

  • After extracting the string first validate the Null condition
    Ex: IF string <> “” use the compare condition ie., string.toLower.trim(“name already exists”)

@shdacak - Any luck mate? did you get a chance to try the posted solutions…??

I had to do strError.ToLower.TrimStart.TrimEnd.Equals(“name already exists”) to get the process to use “Then” but now it doesn’t seem to use “Else” when the condition is False.

When the error appears after selecting submit it stays on the screen but if there is no error the screen will go away. I assumed once the screen disappeared, the bot not being able to find the error message would automatically go to the “Else” process but it is also using “Then”. I even selected ContinueOnError for the Get Text

I even tested it out to make sure it would work just using this condition strError.ToLower.TrimStart.TrimEnd.Equals(“name already exists”):

strError.ToLower.TrimStart.TrimEnd.Equals(“name already exists”) shows as True and uses Then process

Not strError.ToLower.TrimStart.TrimEnd.Equals(“name already exists”) shows as False and uses Else process.

for the above conditions I made sure the Error message would appear when testing but now that the error message is not appearing it is not following the correct process based on the condition