IF Statement Question

Good morning Team,

I have number of pallet conveyors at the facility. I am building a button to allow the user to change the destination of a pallet uing a db update query.

I only want this button to be visible when a pallet is located on a specific set of conveyors.

This expression below works.

if(({../Pallet Info.props.data}[0, 'location']) = 'PT20050', true, false)

My issue is that i want it to look at a selection of conveyors.

Something like this:

if(
  {../Pallet Info.props.data}[0, "location"] = "PT20060" or
  {../Pallet Info.props.data}[0, "location"] = "PT20450" or
  {../Pallet Info.props.data}[0, "location"] = "PT20440" or
  {../Pallet Info.props.data}[0, "location"] = "PT20430" or
  {../Pallet Info.props.data}[0, "location"] = "PT20420" or
  {../Pallet Info.props.data}[0, "location"] = "PT20410",
true,
false)

Use ||, not or in expressions. You also don't need the if:

{../Pallet Info.props.data}[0, "location"] = "PT20060" ||
{../Pallet Info.props.data}[0, "location"] = "PT20450" ||
{../Pallet Info.props.data}[0, "location"] = "PT20440" ||
{../Pallet Info.props.data}[0, "location"] = "PT20430" ||
{../Pallet Info.props.data}[0, "location"] = "PT20420" ||
{../Pallet Info.props.data}[0, "location"] = "PT20410"
2 Likes

Ryan,

Thank you for the help. How would I know to do that? Is that a json thing vs. an SQL query thing?

I do see it in the logical operations, i just did not think to use that.

It's an Ignition expression language thing, roughly reminiscent of Java but not quite.

2 Likes

There's no json or sql involved here. It's only an expression, which is an ignition thing. See the link posted by Felipe above.
Do not confuse it with python (actually, jython), which is used for scripting.
You'd use or in python, and || in expressions.
Which you should be careful not to confuse with |, which has the same meaning in both python and expressions.

or and || are a logical or, used to check if at least one of 2 operands is true.
| is a binary or, used to do a bit wise processing of 2 operands (b1010 | b1001 results in b1011)

4 Likes