How to replace a NULL value in an if condition

Hello,
I have written a rule in which I query certain parameters. However, now and then it comes to NULL values.
So e.g. if(x<NULL) does not work and it leads to errors.
First I have tried:
if(X.state < Y). If Y is a NULL value = error
Then I tried:
if(X.state == NULL || X.state < Y) hoping that would work, but it runs into the same error.

I know in SQL there is the IsNull function that replaces the NULL value e.g.:
if(IsNull(X.state,0)<Y).
Is there something like that here too? How can I realize that any NULL values are reliably caught?

Forget that kind of approach. NULL is a special but perfectly valid state for an Item.

This kind of approach should work. Beware making assumptions about “same error”,rules error reporting is ambiguous.
Explore it one step at a time.

if (X.state == NULL) {
   logInfo("test", "My Item has NULL state")
}
// do some more code

Bear in mind state can also sometimes be UNDEF which requires similar treatment.

Okay, then I guess I’ll have to take the code apart piece by piece.
Was hoping to get around that since the code already has quite a few lines :wink:
But thanks for now!

You didn’t say what language you are writing rules in and the examples here are ambiguous. Could be Rules DSL, could be JavaScript. Rossko57’s code is definitely Rules DSL.

There actually is a one liner where you can test for NULL or UNDEF in the same comparison by checking the state’s class. In Rules DSL

if(X.state instanceof UnDefType)

In JavaScript

if(X.state.class() === UnDefType.class())

or something like that, I’m going from memory.