Creating a Process variable reusable all over the process


#1

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


#2

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.


#3

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…


#4

How do you currently start the process?


#5

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.


#6

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"
}


#7

Thanks Niall,

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


#8

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


#9

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 ?


#10

@JulesCesar44 are your fine with using scripting?


#11

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