Set variable with process instance id



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 (,%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?


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:



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


Hello @Ingo_Richtsmeier,

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



Hi @xndrexs,

no, user tasks IDs a different from execution IDs. A user task references an execution by its ID in the database.

Hope this helps, Ingo