Set businessKey from start message event

Hi,

I am using Flowable 6.6.0
I need to set a businessKey for my processes.
My process can be started from two different ways:

1/ Programmatically through:

runtimeService.createProcessInstanceBuilder()
                .businessKey("myBusinessKey")

This way, I successfully set the businessKey.

2/ Through start message event
Here, I don’t know how to set the business key.

I tried:

runtimeService.updateBusinessKey(execution.getProcessInstanceId(), "myBusinessKey"));

but I can’t retrieve the process from the History service. I guess the process is already started and the key is not updated in the History service.

Is there a way to set the businessKey when the process starts from a “start message event” (Kafka) ?

Thanks!

Michel

Any help on this would be appreciated.

Hi Michel,

you can add a service task right after (Message start event) → (…) to set business key to the expected value.

Regards
Martin

Thanks Martin.

I set the businessKey in a service task right after the message start event.
However, when I use the historyService to get the historyProcessInstance , I am not getting any result.

historyService.createHistoricProcessInstanceQuery()
                    .processInstanceBusinessKey(businessKey)
                    .includeProcessVariables()
                    .singleResult();

The flow is synchronous from this service task. Is it the reason the historyProcessInstance is not updated with the business key?

By the way, I am querying the historyService with the business key in order to check the status of the process instance (running/done).

If history works (turned on, on the right history level, synchronous history…), it should work. If not could you try to reproduce the issue in the jUnit test?