Camunda: How pass variable from parent process to subprocess. (which is started by event)

I have process which create sub process by event, I would like to pass variable from parent process to subprocess. One way which I found is by using

MessageCorrelationResult result = runtimeService
    .createMessageCorrelation("newEvent")
    .setVariable(TOUR_ID, id)    //trigger instance where customer matches
    .correlateWithResult();
runtimeService.setVariable(result.getProcessInstance().getId(),"variableToSend", "val");

but result.getProcessInstance() returns null, it seems this is a known issue. https://app.camunda.com/jira/browse/CAM-7772

Do you know how can I pass variables from parent to sub process using other approach ?

Original question on stackoverflow.

Hi,

#setVariable does already what you want, see the Javadoc: https://docs.camunda.org/javadoc/camunda-bpm-platform/7.9/org/camunda/bpm/engine/runtime/MessageCorrelationBuilder.html#setVariable(java.lang.String,%20java.lang.Object). For matching a variable for correlation, you would use #processInstanceVariableEquals and similar methods.

Cheers,
Thorben