Creating a Process variable reusable all over the process

Hi,

I would like to create a variable called Variable (Text) at the beginning of the process
And be able to update the value of this variable and read it all over the process for example in XoR gateways.

Is that possible? (Without using Java or Scripting) just with the native features of Camunda

Thanks

1 Like

That’s the default behavior of all process variables.
Once created or passed as a payload to start a process they’re available throughout the process.

Thanks Niall.
The problem is that I don’t know a simple way to create those variable without using any script. I thought Camunda would provide natively this feature…

How do you currently start the process?

Well I start it from a custom back office which interacts with Camunda. It gives the Entity on which the process runs. We can use the Entity values by calling java classes but sometimes I just need local process values to deal with business rules in the process. In that case I would like to create Camunda process variables. The way I found know is to use groovy script but I guess there must be a simple way to do it with Camunda properties.

Well if you want to start a process via Java and pass it variables it’ll look like this:

    	 Map<String, Object> processVariables = new HashMap<String, Object>();
    	 processVariables.put("varOne", "Variables are great!");
    	 
    	 processEngine.getRuntimeService()
    	 .startProcessInstanceByKey("YourProcessKey","BusKey", processVariables);

You can also do the same thing via the REST API with the following

POST /process-definition/aProcessDefinitionId/start

{"variables":
    {"aVariable" : {"value" : "aStringValue", "type": "String"},
     "anotherVariable" : {"value" : true, "type": "Boolean"}},
     "businessKey" : "myBusinessKey"
}

1 Like

Thanks Niall,

I was thinking it could be possible without using any coding. Just with the default system services tasks…

I was thinking it could be possible without using any coding. Just with the default system services tasks…

You could also use an ExecutionListener to set a variable in process scope for example after start event has ended.

Best regards,

Markus

The original question of Mokhtar is perfectly relevant and has not been answered i think. Without using any Java code or REST API, how can I set variables in Modeler ?

@JulesCesar44 are your fine with using scripting?

Hi @JulesCesar44

as already mentioned, you could use a execution listener which listens on end event of process start event.
You could use a expression like this:

${execution.setVariable(‘Variable’, ‘Some Text’)}

I don’t know if this is scripting from your point of view but it is a possibility to add a variable without writing any java code.

Best regards,

Markus