JavaScript for DMN input expression results in DMN-01002 Exception language ECMAScript

If a DMN input expression does not exist as variable of the process instance - I get an exception.
It works fine, if I check this in a JavaScript-task before the DMN and generate a needed variable if it does not exist.
But can I do this directly in the DMN ?

The following JavaScript works as JavaScript-Task but not here as JavaScript Expression for the DMN input:
execution.setVariable(‘DriverCode’,(execution.hasVariable(“DriverCode”) ? execution.getVariable(“DriverCode”) : “”))

=> Result is an Exception:
org.camunda.bpm.dmn.engine.impl.DmnEvaluationException: DMN-01002 Unable to evaluate expression for language ‘ECMAScript’: ‘execution.setVariable(‘DriverCode’,(execution.hasVariable(“DriverCode”) ? execution.getVariable(“DriverCode”) : “”))’

or what is the best way to prove if the input variable exists to avoid an exception in the DMN ?

Hi @tpelzer,

the script doesn’t work, because you don’t have access to the execution in DMN.

By default, the input expression is evaluated as JUEL expression. An equivalent JUEL expression would look like:

empty DriverCode ? DriverCode : ""

However, you can also deal with null inside the decision. See the related post for details:

Best regards,

1 Like