AnsweredAssumed Answered

Scope on Message within Subprocess

Question asked by esseti on Feb 16, 2015
Latest reply on Nov 25, 2016 by royqh1979
Hello all.
As far as i understood setVariable() creates global variable, while seVariableLocal() creates a variable with the scope that is the partent object, so if it's within a subprocess it's not accessible from outside.

Now, the receive message task (or a catch message event) seems to use setVariable when it receives a message, am i correct?

i made this test https://www.dropbox.com/s/3kg6h2kepq8p4zh/Screenshot%202015-02-16%2011.02.54.png?dl=0
the script tasks prints the variable "mydata" (first appends "t1", second "t2", third "t3")
and i've a java class to execute the process that has this piece of code:


List<Execution> list = runtimeService.createExecutionQuery().processDefinitionId(processInstance.getProcessDefinitionId()).messageEventSubscriptionName("message").list();
   int i=0;
   for (Execution execution : list) {
      Map<String, Object> data = new HashMap<String, Object>();
      i++;
      System.out.println("sending "+i);
      data.put("mydata", "loop " +i);
      runtimeService.messageEventReceived("message",execution.getId(),data);
   }


what i have as output is:


sending 1
t1: loop 1
sending 2
t1: loop 2
t2: loop 2
t2: loop 2
t3: loop 2


as you can see the second receive in the first subprocess loop (the first t2) "prints 2", while it's the subprocess that received "loop 1". my understanding is that the variable is global, then it's overwritten by the second t1 receive.

Now: How can i set the receive message to store the variable local for the subprocess, thus the output will be smt like:


sending 1
t1: loop 1
sending 2
t1: loop 2
t2: loop 1
t2: loop 2
t3: <error or null or dunno>

Outcomes