Switch Statement

uiautomation

#1

Good afternoon, I tried switch statement and in the expression I am trying to do nested If statement like:
If (gender=“F”, If(Married, “Mrs”, “Mr”) , “Mr”).

For the same I have created two variables gender and Married of type String. While I am trying to run code its giving following error:

The workflow has validation errors. Review and resolve them first.

System.Activities.InvalidWorkflowException: The workflow has validation errors. Review and resolve them first. —> System.Activities.ValidationException: Compiler error(s) encountered processing expression “If (gender=“F”, If(Married, “Mrs”, “Mr”) , “Mr”)”.
Option Strict On disallows implicit conversions from ‘String’ to ‘Boolean’.

I followed the instructions in UI Path Best Practice Guide, please help me solve the issue.

Thanks in Advance :slight_smile:


#2

Hi,

If(Married, …

Married would need to be a Boolean type like True or False. Have you verified that? If you want it to be a string, then change it to something like Married=“Y” or similar.

Regards.


#3

Hi Clayton,

I tried changing the type to boolean as well then following error is shown:

The workflow has validation errors. Review and resolve them first.

System.Activities.InvalidWorkflowException: The workflow has validation errors. Review and resolve them first. —> System.Activities.ValidationException: Compiler error(s) encountered processing expression “Married”.
Option Strict On disallows implicit conversions from ‘Boolean’ to ‘String’.

— End of inner exception stack trace —


#4

That error shows that you have a field that is supposed to be a string but is a Boolean. Also check that your Switch type is set to String.

Could you provide a screenshot of the activity with the validation error and the details around that activity? That would make it easier to solve your issue.

Thanks.


#5

Variable Input

When I give input as F for Gender Message Box still returns Mr instead of Mrs as I have already set the default value of Married to True.

Regards,
Suyash Porwal


#6

Hi,

The Expression looks correct. Have you tried showing what gender and/or Married.ToString is in a message box? It’s possible gender didn’t get stored correctly.