if in calculated attribute

Deboraha year ago

Hello,

5.6 I saw that the old IF syntax in calculated attributes is no longer supported.

For example I had this attribute:

If(io87)
  {
  }
else
  {
     return io87
  }

How can this be done now? From the JEXL syntax it still seems to be allowed (https://commons.apache.org/proper/commons-jexl/reference/syntax.html)

I also have some nested ifs that I wouldn't know how to convert

Thanks!

Anton Tananaeva year ago

You can use the ternary operator:

io87 ? first : second
Deboraha year ago

Thank you, it works. How come this expression truncates my decimals?

io83 ?? io83/10.0F

Instead by leaving only io83/10.0F the final result correctly has one decimal place.
The output is always of type number

Anton Tananaeva year ago

Are you sure the result is truncated? Or the UI just displays one decimal place? Check the API or the database.

Deboraha year ago

These are the two tests done directly from the attributes page

https://ibb.co/HgSV0yf
https://ibb.co/8Dfc8VZ

Anton Tananaeva year ago

Oh I see. Your expression doesn't really make sense. It always uses the original value.

Deboraha year ago

I would basically need the attribute to be calculated only if io83 exists. Are there any other solutions?

Anton Tananaeva year ago

In that case your expression is completely incorrect. The right solution would be something like this:

io83 ? io83/10.0F : null
Deboraha year ago

thanks it work