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?
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/