Add a variable using ProcessInstance Id

Hi!

I’m trying to add a global variable to an existing process using ProcessInstanceId, but I can’t find the way to do it. RuntimeService uses the executionid for this, which I don’t have. I checked the rest api, and there is Camunda Platform REST API
which seems exactly what I need, but I fail to find the Java API counterpart for it.

I know I can add variables from delegates, when creating the process, etc, but my use case is to add a variable before deleting a processinstance because of an external event (related to other question I asked, Restart Process Instance adding a new variable)

Thanks!

Juan

Ok, turns out that RuntimeService first parameter can be executionId or processInstanceId according to https://docs.camunda.org/javadoc/camunda-bpm-platform/7.10/org/camunda/bpm/engine/RuntimeService.html#setVariable-java.lang.String-java.lang.String-java.lang.Object-

So runtimeService.setVariable(processInstanceId, "variableName", "variableValue"); works just fine.