Case statement help

I have this case statement:

case({view.params.Line} && {view.params.Pos},
11 && 1,
111,
11 && 2,
112,
11 && 3,
121,
11 && 4,
122,
11 && 5,
131,
11 && 6,
132,
11 && 7,
141,
11 && 8,
142,
999)

It always returns a 111. Is the case statement evaluating the first line and not the rest? I am trying to use a flex repeaters input params to change a labels text.

Try this

case(concat({view.params.Line},{view.params.Pos}),
	"111", 111,
	"112", 112,
	"113", 121,
	"114", 122,
	"115", 131,
	"116", 132,
	"117", 141,
	"118", 142,
	999
)
1 Like

What are you expecting the result of this operation to be?

&& is the Logical AND operator, 11 && 1 would evaluate to True.

& is the Bitwise AND operator, 11 & 1 would evaluate to 1.

I would do the same but with a divider between the 2 numbers such as a | or , so that 1 and 11 don't evaluate the same as 11 and 1 for any future addition to the case statement. Instead you would get 1|11 and 11|1

1 Like

I was looking for what @dkhayes117 has. Looks like I needed to concat the two params. It was my first time trying to use a case statement like that.

Tidying up a bit makes it easier to see what's a case and what's the result ...

case({view.params.Line} && {view.params.Pos},
  11 && 1, 111,
  11 && 2, 112,
  11 && 3, 121,
  11 && 4, 122,
  11 && 5, 131,
  11 && 6, 132,
  11 && 7, 141,
  11 && 8, 142,
  999
)

However, if you test your logic as shown below you might find that it doesn't work as you think.

Bitwise AND

Every one of those case conditions evaluates to true.

understood, thanks

Another way would be to maintain a top level dictionary in a project script which would take the numbers and find the matching dictionary key then return the value. The expression would use runScript(), that way you could change your lookup dictionary without modifying your expression bindings.

that would look like this

someProject //script package name

myDict = {"11|1":111}

def lookupOnLinePos(line,pos):
    key = '%s|%s' % (line,pos)
    return myDict.get(key,999)

//in the expression
runScript("myProject.lookupLinePos",
    0, //only run when parameters change (poll off)
    {view.params.Line},
    {view.params.Pos}
)

I guess you could manage it with a DB table too.