Use variable with null object


I use a script task in my process where the name of the result variable is result. I use Groovy.
My problem is if the return value is null the Camunda doesn’t create the result variable.
Do you have any idea how can I force to create the result variable with null value?

In my next script I would like to check the return value and the if (return == null ) expression is not working because the Camunda said the the result variable is not existing.

An example process:

Thanks in advance: Gábor

Hi Gabor,

you can create the variable before the script task or explicit inside the script via execution.setVariable().

Does this help you?

Best regards,

I’m not sure if this helps - it’s an HTML example using Camunda’s library:

Noting that this is a slightly modified example from Camunda’s samples.

<div class="controls">
                    <input class="form-control" required type="text"
                        cam-variable-name="myVariable" cam-variable-type="String"
                        placeholder="myVariable" ng-minlength="2"
                        ng-maxlength="50" />

And a Java example - via a basic ReST interface

    public String bpmEchoGet(@PathParam("processID") String processID, @PathParam("hello") String hello) {"*** bpmEchoGet - processID: " + processID);"*** bpmEchoGet - hello: " + hello);

        ProcessInstanceWithVariables pVariablesInReturn = runtimeService.createProcessInstanceByKey(processID)
                .setVariable("hello", hello)

        String piid = pVariablesInReturn.getProcessInstanceId();

        return "{\"processInstanceID\": \"" + piid + "\"}";



This is a workaround what I use but in my opinion not a nice one.

Regards: Gabor
2017.03.07. 14:54 ezt írta (“Philipp Ossler”

@Gabor_Sandor what about storing your data in a Object? (such as a SPIN object) ?

Storing the following as a JSON SPIN object:

   'myResponse' : null

can you could get your response as:


Which will return null or your expected value.

as per:

I’d say this should be changed in the engine. If you define a result variable and your script returns null, then the result variable should have value null. The current behavior is not consistent. Feel free to raise an issue in our JIRA.