Struggle with a Switch

I’ve been struggling with this for days. About to pull my hair out.

THIS WORKS

switch({myProperty},
1, 2,
“x”, 22,
99
)

THIS DOES NOT WORK

switch({myProperty},
1, 2,
22, ‘x’,
99
)

and returns:

Type mismatch: Argument 4 for function ‘switch(etc…)’ is an invalid type

please send help!

Seems like in the second example you’re trying to return mixed types as the result of the switch function.

OK, I got it to work by putting every return in quotes, even the numbers. It screwed me up because sometimes mixed types work!

This works:

switch({MyProperty},
1, 2, 3, 4, 5,
‘a’, ‘b’, ‘c’, 44, 55,
‘none’
)

This doesn’t work:

switch({MyProperty},
1, 2, 3, 4, 5,
11, 12, ‘c’, ‘d’, ‘e’,
‘none’
)

it seems as long as the last value is an integer, it’ll work…

But I have it working by putting all the returns in quotes. Thank you!

Yeah, the reason the first example worked is that since you started with a String, it was able to cast the other integer values into that same (String) data type. As soon as you “set” the data type with that first value as an Integer, the usage of a String value broke it (since the system can’t convert “x” to an integer value automatically). Glad you got it working!

1 Like