Best Practices to create multiple if statements

Hello!

I have a case that requirements to fill a specific form for a state. I have 10 states each one with its own form. I set a variable “state” which will indicate me which form I need to use. For ex: if state = CA then use CA form.

This being said, I’m looking for best practices on how to create that. My first idea is to create 10 IF statements. Ex:
IF state = CA; then use CA form;
If not IF state = FL then use FL form;
IF not IF state = CO … and so on until all the 10 states are completed.

Any recommendations? And/or better approach?

Thank you!

@icosinga

Use Switch Activity to do this. It’s very efficient one.

2 Likes

You can add multiple IF conditions in a code block and execute the code instead of having activities which makes workflow lengthy and ugly.

Please refer Foundation training in UIPath Academy which explains this.

Regards,
Karthik Byggari

image

Make sure you set the activity’s properties’ “TypeArgument” to String.

2 Likes

Thank you, Karthik!
Do you know where I can find an example?

Check this post for sample -

1 Like

I agree with using a Switch instead like @lakshman and @x.Rei.Ai.x showed. Even if you used Invoke Code, the Switch block would make more sense logically.

You can use the Flowchart Switch or the Sequence Switch. The Flowchart one is an interesting way to visually show how your logic is moving.

Regards

4 Likes

Thank you everyone!!! Great info!

1 Like