Use of UiPath Switch condition/ Flow Switch

Hi Community,

I am getting a String in my work flow. which is ideally one or 2 lines of string value.
Eg: StringValue = “Error: The program failed to execute because of the change in Schema”.

I have list of Error Messages in the “constant” tab of Config File. 7 different Error Messages.
I need to check whether the above StringValue which I got is part of the Error Messages list in the Config file.If the String matches with any of the Error Messages, Then I need to certain action. Likewise, For each Error Message, I need to perform separate action.

How to approach this? I tried using Switch/Flow Switch. But I had to use “.Contains” function in the Experession and not “.Equals” since the Error Messages are more than 1 line. If I use “.Contains” in the Switch, It results in a Boolean. I could get only 2 results (True/False) out of one Switch. But I have 7 different Error scenarios in this case.

Kindly help me out with a solution.
Thanks in advance

Hi @besakkiappan46

1.Take an Assign activity
StringValue = “Error: The program failed to execute because of the change in Schema”

2.Create a list of your error messages
ErrorMessages=New List (OfString)From{“dbkwdhwk”,“dggwigwiugi”…}

3.Take If activity
ErrorMessages.Any(function(s) StringValue.ToLower.Contains(s.ToLower))

In then block

Take For each activity in that give ErrorMessages List

continue the next process

I hope you understand!!

@besakkiappan46

You can use the switch case like this

You can use switch case as below

  1. Create a list or array of error messages you have say listvar
  2. Now in if condition expression use listvar.Any(function(x) x.contains("errormessage))
  3. On then side use switch activity with listvar.IndexOf(listvar.Where(function(x) x.contains("errormessage"))(0)) this will give the index of the error message
  4. In the cases use the number 0,1,2,3,4 as case numbers and depending on the index of error message the switch will change

Hope this helps

Cheers

Hi @besakkiappan46 - You can use switch activity with .equals condition

I assume since the error messages is coming from a config variable, those must be saved in a config variable. Within the switch activity use below condition

If(Config("ErrorMessage1").ToString.Trim.Equals(ErrorMessage.Trim), "ErrorMessage1", If(Config("ErrorMessage2").ToString.Trim.Equals(ErrorMessage.Trim), "ErrorMessage2","Default"))

ErrorMessage is the variable that have some error

I’ve attached the sample workflow for ref

SampleWorkflow.zip (21.4 KB)

Hi Anil,
Thanks for Responding.

The code is largely working. but I face an issue while checking the “IF” condition.
Below is the result I got:

ErrorText.Trim
“Canvas schema version has changed from last extract. Previous: V2.0.1, Current: V1.0.9”

ListOfErrors

List(7) { “Canvas schema version has changed from last extract. Previous:”, “Canvas extract must be complete and from today. Current extract was last updated at:”, “One or more new source table schema different from a target table schema.”, "rows failed to load exceeding limit of ", “One or more source table row counts different from a target table row count.”, “One or more source table columns not different (not encrypted) from a target table column.”, “file does not exist, but table data is required, aborting load” }

The ErrorText which I got matches with the 1st item in the List. Though it is not an exact match, Until the text “Previous:” , It does Match.
But It still goes to the “Else” part of the condition.

Can you help me sort this out.

@besakkiappan46

Okay so i guess you need to match other way round

listvar.Any(function(x) "errormessage".ToLower.contains(x.ToLower))

Change the condition similarly in where as well

Inside then

listvar.IndexOf(listvar.Where(function(x) "errormessage".ToLower.contains(x.ToLower))(0))

Hope this helps

Cheers

You want to use Else If, not Switch. Your logic is backwards to how a Switch works.