Computed Attributes, testing variable before condition

jcorreajr7 years ago

Hello, I am testing the computed attributes.
In my case, the 'alarm' attribute is not sent in all positions generating an alert in the log when it is not present.
"Undefined variable alarm"

In the documentation at: Computed Attributes
In the recommendations part, this case is commented on.

I have no development experience, but I researched jEXL syntax and did not find a way to test the condition of whether or not the variable exists.

Can someone try to help me?

I currently use the following expression:
alarm == "sos" ? "SOS1" : null

jcorreajr7 years ago

I believe I was able to solve the problem in the following way:


alarm ?
  alarm == "sos" ? 
   "SOS1" 
  : null
:null

If someone knows in a more elegant way

Anton Tananaev7 years ago

I don't think there is any better way.

Jose B6 years ago

Hi
I tried the code "alarm ? alarm == "powerOff" ? "off" : null :null" but field returned "alarmOff" , the computed attribute mix someVariable (alarm) already presente on system with my text ("off") instead of replace the value of all the field. There no erros on logs.

For me no make sense.

JB

Anton Tananaev6 years ago

It's not possible. You must be missing something.

Jose B6 years ago

Hi Anton,
Please, Could you test and you see by yourself?

JB