Local Variables in DMN?

235 Views Asked by At

Can we initialize local variables inside a dmn using FEEL/Literal expression

if (somecondition) then {
  newVar=newVal
}else { }

if(newVar==someVal) then {..}
else {}

Can we initialize local variables and use them the way it is done in OOP? I need to utilize the local variable, I do not intent to use BKM here.

1

There are 1 best solutions below

0
On

DMN FEEL is an expression language and as such it does not have statements, specifically variable assignment statements.

Can we initialize local variables and use them the way it is done in OOP?

This is indeed a typical statement in java such as

String name = "John Doe";

and being a statement is not available in the FEEL expression language.

That said, in special scenarios, you might use an helpful trick of inlining a FEEL context to mimic similar behaviour.

Something ~like:

{
  newVar: if (somecondition) then ... else ... ,
  result: if (newVar=someVal) then ... else
}.result

For example:

{
  newVar: if (a number > 0) then "pos" else "neg" ,
  result: if (newVar="pos") then "positive" else "negative"
}.result

if supplied with a number would result in the value "positive" or "negative" FEEL string, with no trace of the newVar or the "pos" or "neg" in the final result.

Demo: enter image description here