Best practice for using Switch Activity with multiple boolean values

Hi All.

I’ve previously built processes that use boolean values to confirm which path the process should go towards when an error is encountered. After holding a QA Review with one of the senior developers on the team he pointed out that using Nested If Statements is messy and to use a switch activity to manage all the values and paths.

I’ve used the Switch Activity in the past, mainly with numerical values but I have not used it for boolean values. I’ve noticed though that only one boolean expression can be assigned to a switch activity resulting in only 3 cases (Default, True or False).

I was wondering if there was a way to use 1 switch activity to deal with multiple booleans?
I’ve attached below how the process currently looks with the nested if statements.

Thanks in advance!

Hi.

Each of your Booleans are a different expression.
You have 2 choices I think. You can migrate your logic to a Flow chart and use Decisions instead of nested If activities (this can still be messy sometimes), OR place all your booleans into an expression that returns a number or string.

Nested Decisions that all use the same steps if TRUE would look like this:


And you can have extra steps for each decision in the True

A Switch in a Flowchart would look like this:

A Switch in a Sequence would look like this:

Eh, probably last option using Switch might be cleanest, if all you are doing is Logging some different information.

Regards.

5 Likes

Thanks for providing a range of answers ClaytonM.

I tried the bottom recommendation for using the multiple boolean values in a switch activity to no avail. The process always proceeds down the default path which currently provides a generic error handling message, rather than one of the other cases which logs what the error is and provides more context.

I was wondering how the logic works that you’ve outlined in the the switch explain above. Have you linked a boolean value equaling true to a string value to use in the switch case? If so what would the opposite be? Meaning if I wanted a boolean to be false before going down a specified case path in the switch activity.

Looking forward to your response.
Rashid

I’ve realised that instead of using a boolean value as a flagger I can set a variable (strError) with a differing value depending on the error that’s been encountered. From there I can set that value as the expression in the switch activity and set the necessary case sequences.

Thanks for the support @ClaytonM.

1 Like

Good point, you can just use a string variable, then use that as the expression in your switch.

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