cancel
Showing results for 
Search instead for 
Did you mean: 

How to access execution variables from subprocess

hiravgandhi
Champ in-the-making
Champ in-the-making
I have a few variables set on the DelegateExecution and I would like to be able to read them from my subprocesses which are invoked through a call activity on the main process. How do I ideally set up the call activity and subprocess to allow me to use calls such execution.getVariable("foobar") and execution.setVariable("foobar", foobar)?
5 REPLIES 5

frederikherema1
Star Contributor
Star Contributor
You'll need to define which variables you want to "receive" from the parent-process to use in the sub-process. And if you want to have variables from the sub-process flushed to the parent when the subprocess ends, you'll have to declare them as well.

See userguide for the exact format: http://www.activiti.org/userguide/#bpmnCallActivity


<callActivity id="callSubProcess" calledElement="checkCreditProcess" >
  <extensionElements>
          <activiti:in source="someVariableInMainProcess" target="nameOfVariableInSubProcess" />
          <activitiSmiley Surprisedut source="someVariableInSubProcss" target="nameOfVariableInMainProcess" />
  </extensionElements>
</callActivity>

I am a little confused. What is the scope of these variables being passed? For example, if I want to pass certain variables that are on the execution variable, do I pass execution as a whole (target="execution"), is there some special syntax to just pass certain variables that live in execution (target="${execution.getVariables('foobar')}") or is it assumed that the variable I am passing lives in execution? (target="foobar")

frederikherema1
Star Contributor
Star Contributor
When using activiti:in, it's assumed that the variable with the name defined in source lives on the execution that creates the call-activity OR in a parent of that execution (goos all the way up to the process-instance). The value you put in "target" is the name of a variable that will be created in the sub-process when it's started, based on the source variable-value.

When using activitiSmiley Surprisedut, the source contains a variable name that is present in the sub-process root-execution. The value in "target" is the name of the variable that will be set on the execution that created the sub-process in the first place, based on the value of the source-variable.

Does that make sense? So the "source" and "target" except a variable name, not an expression. If you want to have a custom "source", which is not just a variable, you should use "sourceExpression":


<activiti:in sourceExpression="${myBean.calculateDistanceTo(destinationAdress)}" target="distance" />

If you use the code above, the sub-process will be started with a single variable set, called "distance". The value of the variable contains the result of the calculateDistanceTo on the "myBean", passing in the process-variable "destinationAdress" to the function-call.

guillaume1
Champ on-the-rise
Champ on-the-rise
Hello,

From the documentation, and as it is written in this thread, I need to configure the callActivity task with the variables I want to transfer to the subProcess.

But what should I do if I want to provide all the variables declared in the parent to the subProcess and if I don't know in advance which these variables will be ?

takt
Champ in-the-making
Champ in-the-making
duplicate