Default value for dmn input variable, which is null

Is there a way to set a default value to a DMN input variable if it is null. By null I mean that this variable is not present in the execution context.
The variable is called effectiveCosts. It is not created in every process. But each process goes through a DMN table that needs the variable effectiveCosts.
Therefore, I want to give this variable a “default value” of 0.

Is this possible with an input expression in the DMN table?

Dear Sven,
welcome to Camunda forum!
Yes it’s definitely possible to achieve what you are trying to do.
In the “When” expression of your Decision table you can use the following expression:

if effectiveCosts = null then 0 else effectiveCosts 

In the documentation page here you can see the following statement:

Any value can be compared with null to check if it is equal to null , or if it exists.

Hope it helps!
Enricio

Hi Enricio,

Thanks for your help!
I already tried this solution. Sadly, it always returned null, even tough the variable effectiveCosts was available at runtime.

The following solution worked for me:

if is defined(effectiveCosts) then effectiveCosts else 0

I hope this helps for someone else :slight_smile:

Hi Sven,
I’m happy you have found a solution,
but also mine is working, since I’ve tested it before sharing it :grinning:
Which version of Camunda are you using?