Is there a way to get the parent execution given an execution id?


I’m wondering if there is a way to get the parent execution of an execution in camunda. What I’m trying to achieve is basically the following:

This is a simple process involving a parallel gateway. Each of the flows is composed of a service task (external) and a user task.

In each “Pre: Task X” service task, I want to set some variables that I will use afterward in their respective user tasks. I want each execution flow of the parallel gateway to have their own variables and non-accessible from the other flows. How can I achieve this?

I was doing some tests and I found the following:

When the process is instantiated, I get instantly 5 execution instances. What I understand is that one belongs to the process, the next two belong to each flow of the parallel gateway, and the last two belong to each of the service tasks.

If I call “complete” for one of the service tasks on the REST API with localVariables, they will instantly disappear and no further be available because they will be tied to the execution associated to the external task, which is terminated after the task completion.

Is there a way in which I can get the parent execution of the task, which in this case would be the parallel execution flow. So I can set localVariables at this level?

Thanks in advance for the valuable help



Hi @jsquinteroa,
Local variables are only visible within scope they are created - that’s why you cannot access them when leaving Pre: Task x tasks. You can try set up a variable (not local) in a Pre: Task X (let’s say varX) and then define input parameters for each tasks with your local name using following expression as value ${varx}.


Hi @Kikol
Thank you for answering

So, in the end, do I have to depend on process (global) variables? Isn’t there a cleaner way to isolate each of the parallel flows? What I was hoping for is that there could be a way, to go through the executions hierarchy, get the one I’m interesting in and then call this in the REST API in order to set local variables in that scope (The parallel execution flow). Isn’t there another way that let me assign local variables at that scope without using Java classes?


Using global variables is not a bad choice unless you do not use multi instance tasks/sub-processes. If you do so, then input variables approach will help you. Please keep in mind that local variables dies when task is finished. Then you can obtain variable value only using variable instance list using processInstanceId and/or activityInstanceId.
You can also opaque your parallel execution into a sub-process and create variables in a sub-process scope.


Not sure if I’ve understood this correctly so apologies if I’ve missed the point.

If you put each “Pre: Task XX” and “Task XX” pair into their own subprocesses and declare whatever local variables as uninitialised input variables on each subprocess, you will then be able to set them in the service task and pick them up in the user task. When the user task completes, the local variables are destroyed with the subprocess.


Thanks @IanS and @Kikol again for your replies

I was just checking out and it seems also legit to do what you say (Creating sub-processes and creating variables at each subprocess scope). I found an even easier way for my particular use case, and it was by registering execution listeners at each of the parallel sequence-flows (take event) with the expression ${execution.setVariableLocal(‘myVar’, ‘myValue’)}. With that config, I was able to access the variables properly on each of the flows.

Nevertheless, I still feel it should be nice to have a better way to work with the executions hierarchy through the REST API

Best Regards