Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update process instance variables?

I'm using Camunda Java Api, and i would like to change a process instance variable for a running process, is it possible ?

like image 597
Sfayn Avatar asked Oct 22 '25 15:10

Sfayn


2 Answers

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.

like image 142
Jan Galinski Avatar answered Oct 24 '25 06:10

Jan Galinski


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);
        });
    });
like image 42
Sfayn Avatar answered Oct 24 '25 05:10

Sfayn