AnsweredAssumed Answered

Global variables of multi-instance and callActivity?

Question asked by ryu on May 22, 2011
Latest reply on Feb 27, 2017 by maheshramani
activiti:out in a callActivity allows the possibility to write a result from a subprocess back to its parent process.
However, activiti:out does not work in a multi-instance of callActivity, which means there are no ways to write the result back to the main process when you are in a loop.

I think it is very important. One of the Scenario I can think of, is to terminate the loop under some result receiving from a sub-process. For example, when an activity inside a subprocess fails, you may want to set a variable to say the loop to terminate immediately (with <completionCondition>)…

One possible solution I've already tested successfully, is to pass a list from our main to the sub process (well, you can say, pass by the value of a reference)
<callActivity id="callactivity1" name="Call activity" calledElement="subProcess">
        <activiti:in source="list" target="list"></activiti:in>
      <multiInstanceLoopCharacteristics isSequential="true">
By doing this way, every changes to the list inside the subprocess will be visible to the main process. List is now like a global variable for the main and all sub process of the loop. Also, I can trigger the loop to terminate immediately when, for example, the list is not empty as above.

But another problem, when you use a userTask inside the subprocess, then whatever changes to the list before the userTask, the list will be empty after that.
I guess, at the userTask, a transaction is completed and all data are persisted to the database. After that, the list we want to reference to, may be not the same list anymore. The above scenario is for sequential loop. For a parallel loop, it is a little bit different. But I want to discuss about sequential loop first. Any ideas to solve the problems would be helpful.

thank you