cancel
Showing results for 
Search instead for 
Did you mean: 

Process variables vs. embedded subprocess

kzakhar
Champ in-the-making
Champ in-the-making
Hello,

Referring to the old post at this forum (http://forums.activiti.org/content/process-variables-subprocess), I assume the variables set in the embedded subprocess are propagated up to the parent process, so should be visible after subprocess end.

Though, doing the test against the Activiti 5.17.0, I receive the different result - the variable set by embedded subprocess is not visible to parent process.

You can find the bpmn process used in test case in the attachment.

Can somebody clarify that should be the expected behavior here, and whether it is the bug in the Activiti?

Thanks.
5 REPLIES 5

jbarrez
Star Contributor
Star Contributor
Your expression resolves to a static string. It needs to be an interpreted expression like this: ${execution.setVariable('variable', 'someValue')}"

Then it works as you expect.

kzakhar
Champ in-the-making
Champ in-the-making
Thanks for the reply.
I fooled myself trying to isolate a bit more complex scenario. Indeed, setting the variable via execution#setVariable makes the variable accessible.

In my original scenario I do not have access to the execution, I work with ProcessInstance and with org.activiti.engine.task.Task, setting the variables as ProcessInstance#getProcessVariables().put("someVariable", "someValue");

In the case of subprocess, that assignment does not impact the process variables of the parent process.

Is it the only way to fetch the execution based on org.activiti.engine.task.Task#getExecutionId() and set the variables via execution#setVariable? Or via runtimeService#setVariable(pId, "someVariable", "someValue")? Can I somehow make that work via ProcessInstance or Task?

Thanks.

kzakhar
Champ in-the-making
Champ in-the-making
Let me clarify, I expect that all of magic should happend calling the org.activiti.engine.TaskService#complete(String taskId, Map<String, Object> variables, false).

@param localScope If true, the provided variables will be stored task-local, instead of process instance wide (which is the default for {@link #complete(String, Map)}).

So, as stated before if an embedded subprocess shares the same variable context with parent process, and we set localScope to false, then this call should propagate the processVariables up to the parent process.

kzakhar
Champ in-the-making
Champ in-the-making
Oops, sorry for the false alarm, I checked the source code for TaskService and for TaskEntity, all works as expected
<code>
public void setExecutionVariables(Map<String, Object> parameters) {
    if (getExecution()!=null) {
      execution.setVariables(parameters);
    }
  }
</code>

I have to find an issue in my own code.

jbarrez
Star Contributor
Star Contributor
Indeed, in case of using an embedded subproces, the variables are seton the same scope as the process. Not sure why it doesn't work for you. A unit test that demonstrates your problem would help us to understand what you are trying to accomplish.