Reputation: 210
I'm using Camunda Java Api, and i would like to change a process instance variable for a running process, is it possible ?
Upvotes: 4
Views: 6045
Reputation: 11993
The RuntimeService has a method ‘setVariable’ which can be called with processInstanceId, variableName and value.
You can finde the processInstance by using ‘runtimeService.createProcessInstanceQuery()....’, for example by using the process business key.
Upvotes: 5
Reputation: 210
I finally, find out how to update a variable for all running process instance :
List<ProcessInstance> processInstances =
runtimeService.createProcessInstanceQuery()
.processDefinitionKey(processKey)
.active()
.list();
processInstances.forEach(processInstance -> {
List<Execution> executions = runtimeService.createExecutionQuery()
.processInstanceId(processInstance.getId())
.list();
executions.forEach(execution -> {
runtimeService.setVariable(execution.getId(), variableName, variableValue);
});
});
Upvotes: 4