Set variable with process instance id


#1

Hello,

is it possible to set a variable to a process by a given process instance ID with the Java API? Currently I can only set a variable by an execution ID (https://docs.camunda.org/javadoc/camunda-bpm-platform/7.3/org/camunda/bpm/engine/RuntimeService.html#setVariable(java.lang.String,%20java.lang.String,%20java.lang.Object). To achieve this I have to create an execution query with the given instance ID to receive any execution and set my variable to the process. Is this intended?

Example:

List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(instanceId).list();
Execution execution = executions.get(0); //check if null or empty
runtimeService.setVariable(execution.getId(), nameOfVariable, object);

It seems possible with the REST API: https://docs.camunda.org/manual/7.4/reference/rest/process-instance/variables/put-single-variable/

Thanks.
Andreas


#2

Hi @xndrexs,

take the process instance id as execution id and you’re fine.

The process instance id is the root of an execution tree that the engine will create if you use parallel forking or subprocessing.

Hope this helps, Ingo


#3

Hello @Ingo_Richtsmeier,

thank you. That solves the problem. Is it the same behaviour with (user) task IDs?

Andreas