Set variable with process instance id

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 (RuntimeService (camunda BPM Javadocs 7.3.7-ee). 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: Put Single Process Variable | docs.camunda.org

Thanks.
Andreas

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

1 Like

Hello @Ingo_Richtsmeier,

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

Andreas

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

1 Like