I have a process variable that is set to a “null” value in a script task before. In the next service task that varaible is used for an input variable with enabled script format Freemarker. the script looks like that:
${status}
So when executing this I get an Freemarker null exception, because for Freemarker null must be handled explicit. So I tried the following script code:
${status!""}
But now I get an exception when I try to load this workflow definition into the process engine, that the syntax of the script is not correct.
Unable to process script: Error parsing ‘${status!""}’: syntax error at position 8, encountered ‘!’, expected ‘}’
Is it not possible to use standard Freemarker handling for null values here?
Have you tried
${status??}
? Your code assumes that the variable is set and compares against an empty string what must fail as the variable has no value whereas ?? Shall check if the variable is set.
the problem is that if I use ${status!""} or your recommendation ${status??} the workflow cannot be deployed into the processing engine.
When I deploy that workflow I get the following error:
ENGINE-09005 Could not parse BPMN process. Errors: * Unable to process script: Error parsing ‘${status??}’: syntax error at position 9, encountered ‘?’, expected ||||‘true’|‘false’|‘null’|’-’|’!’|‘not’|‘empty’|’(’ | Test_017_Housekeeping.bpmn | line 47 | column 55
thanks for sharing the example. I just remembered that we have a feature which basically breaks your template.
It is possible to provide the script/template source as an expression (see docs). Which means whenever the script text starts with ${ or #{ the engine assumes that the user provides the actual script source as a variable.
That is the reason why your freemarker template is actually parsed as JUEL expression.
Did you just used a freemarker template for the null handling or is it possible in your use case to not start the freemarker template with ${?
thanks for the hint, yes that is the problem. So when I change the expression to ${empty status ? ‘’ : status} it works, because I now use just a JUL expression.
Is it possible to disable the JUL for specific input variables? I use that in an element template and now I have to describe the possibilities of the values in a very complex way, like: ok you can use ${…} but not for the beginning of the value then it is JUL, but else it is Freemarker. That is very confusing for a BPMN developer and properly will lead to a lot of errors.