Get variables content before process finishes

Hello!

I am trying to get the process variables content before the process finishes, while it is executing async tasks.

Let’s say I have a process with 2 tasks in this order: Task01 and Task02.

Task01 is synchronous, and Task02 is marked as “Asynchronous before”.

Task01 creates a process variable named Var01 and set a value “Hello!”.

Then I start this process using Java API using the following Java statement:
runtimeService.createProcessInstanceByKey(“processIdentification”).executeWithVariablesInReturn();

I noticed that after Task01 completes, the statement createProcessInstanceByKey returns the thread execution to my Java program, but var01 is not returned in the instance that the method returns.

I also noticed that after Task02 completes and the process finishes, I am able to get the variable var01 using the History Service from the Process Engine, but I need to get the var01 content as soon as the thread execution returns to my Java program, is it possible to do without making both Task01 and Task02 synchronous?

Thanks!

Fernando

Is that Task01 is an user task?

Where else in the process model do you have “async before” or “async after” set?

Both Task01 and Task02 are Service Tasks.

Only in Task02.
Taks02 is configured as “async before”

Hi!
These asynchronous continuations indicate a save point / transaction boundary. Naturally this will be the “end of a thread”. Due to this you won’t receive the variables after having reached the end event. Now you need to consider whether this is a fair trade-off. :wink:

You should consider working with another bpmn element such as a message sending event / activity. If you are rather looking for something implicitly a listener might be interesting as well.

What do you think about these possibilities?
Best,
Thomas

Under these circumstances, I’d expect the engine to return the variables. You can create an issue on camunda’s jira so that developers can analyse your case.

Can you show the code how you set the variables?