Understanding variables

hello community,

i often end up in my application tests with null values when i pass variables to my subprocesses. today is the day i want to talk about my understanding of passing variables. I attached an very easy example process with a subprocess below.

Referring to the camunda guide (Process Variables | docs.camunda.org) it says:

A variable that is defined on a parent scope is accessible in every child scope unless a child scope defines a variable of the same name. The other way around, child variables are not accessible from a parent scope.

So variables from the parent process are available in subprocesses if no variable with the name is given. I actually not expect to fill the variables in input/output parameters –only if i want to modify the value and need it in my parent process. Like it says in your doc:

Input /output variable mappings can be used to create new variables or customize how variables are merged into the process instance.

(i dont need local variables thats why i dont talk about them)

So this was my understanding so far. Lets talk about my example given.

Mainprocess.bpmn (3.3 KB)
Subprocess.bpmn (2.4 KB)

When i run the process the act_hi_varinst table looks like:

But my console prints null:

This behavious makes me feel like i have understand nothing. Am i wrong that i have expected to see the name in the console? Where is my understanding mistake? What am i missing? :frowning:

Hi @Sandra1337 ,

I tried to reproduce the haviour you described in a little testcase but for me it printed the “name” variable correctly.

I used your process models together with the following code (Ikr, it is still JUnit 4 :smiley: ):

public class Demo {
    public static final ProcessEngine PROCESS_ENGINE;

    static {
        StandaloneInMemProcessEngineConfiguration processEngineConfiguration = new StandaloneInMemProcessEngineConfiguration();
        PROCESS_ENGINE = processEngineConfiguration.buildProcessEngine();

    public ProcessEngineRule processEngineRule = new ProcessEngineRule(PROCESS_ENGINE);

    @Deployment(resources = { "processes/Mainprocess.bpmn", "processes/Subprocess.bpmn" })
    public void test() {
        ProcessInstance process = runtimeService().startProcessInstanceByKey("Process_Main");

        complete(task(process), Map.of("name", "Hallo Welt"));

And the result was as expected. The variables from the root process were used to create the subprocess. Thus, the script task prints “Hallo Welt” which is the content of the variable “name”.

13:43:42.277 [main] INFO org.camunda.bpm.engine - ENGINE-00001 Process Engine default created.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass$3$1 (file:/C:/maven_repository/org/codehaus/groovy/groovy-all/2.3.3/groovy-all-2.3.3.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass$3$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Hallo Welt

In short: Your expectation is correct. The “name” variable should be accessible when it was set in the parent process beforehand.

Kind regards

Hi @Adagatiya ,

thank you for your reply. I really appreciate your test!

Glad to know that it is not my understanding. This means the problem is likely in our extended interface.