Use variable with null object

Hello

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,
Philipp

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" />
</div>

And a Java example - via a basic ReST interface

    @GET
    @Path("bpmechoget/{processID}/{hello}")
    @Produces(MediaType.APPLICATION_JSON)
    public String bpmEchoGet(@PathParam("processID") String processID, @PathParam("hello") String hello) {

        LOGGER.info("*** bpmEchoGet - processID: " + processID);
        LOGGER.info("*** bpmEchoGet - hello: " + hello);

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

        String piid = pVariablesInReturn.getProcessInstanceId();

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

    }

Hello

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” forum@camunda.com):

@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:

myVarName.prop('myResponse').value()

Which will return null or your expected value.

as per: https://docs.camunda.org/manual/7.6/reference/spin/json/01-reading-json/#the-different-value-types

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.

Cheers,
Thorben