cancel
Showing results for 
Search instead for 
Did you mean: 

Multi Instance Set Variable On Item In Current Loop

jamie_dulude
Champ in-the-making
Champ in-the-making
Hello All,
I'm looking for a little assistance when using multi instance processes.

Here's my scenario…
The goal of my workflow is to essentially take a list of people and filter that list down based on a series of conditions. So for example, I might start with a list of 100 people and have a result of 5 people that passed all criteria. I'm open to suggestions on how to achieve this. My first instinct was, crap, I'm going to have to start 100 separate instances, one for each person. Then I discovered the multi instance support which is fantastic. So I got to work and build a small little POC and hit a blocker.

Here is a screenshot of the basic POC I created…
https://dl.dropboxusercontent.com/u/33369/Screen%20Shot%202016-02-24%20at%204.32.05%20PM.png

As you can see it's very simple. It can go one of two directions, either the "Keep On List" route or the "Remove From List" (my real work scenario is much more complex).

My problem is, how do I keep track of the items that should be removed?

Here is an example of the json payload I'm setting to start the instance.
<javascript>
{
   "processDefinitionKey":"LoopTest",
   "businessKey":"",
   "tenantId": "",
   "variables": [
      {
        "name": "people",
        "value": [
            {
                "flow": "keep",
                "name": "Person 1"
            },
            {
                "flow": "remove",
                "name": "Person 2"
            },
            {
                "flow": "keep",
                "name": "Person 3"
            }
        ]
      }
   ]
}
</javascript>

My sub process loops over the "people" collection and assigns the element variable to "person". The decision point checks for either ${person.flow == 'keep'} or ${person.flow == 'remove'}.

My hope was that I could use some type of executioner listener to set a variable on the actually person that is in the current loop to indicate whether or not the person should be removed or not, but I can't seem to set variables on the actual person that I'm looping over.

Any advice for me would be greatly appreciated.
2 REPLIES 2

hari
Star Contributor
Star Contributor
Hi,

There are 2 ways I can think of to do this.
Approach 1
———–
You need not go for a sub process but have one service task where in you loop from 1 to n persons and then based on some condition, you remove the unwanted ones from the list.

Approach 2
————
As you have used, make use of a call activity to loop over the persons and in the sub process have one service task to check if the current person object from the collection which was passed as a variable to the sub process can be part of the list or not. If it cannot be part of the list then just remove the person object from the list and overwrite the process instance variables collection with the new list.

jamie_dulude
Champ in-the-making
Champ in-the-making
Thanks for the help. I was able to get it to work by doing something similar to Approach #2. My app that connects to the activiti workflow is written in PHP so I was trying to do everything over rest API calls, but I'm only able to get it to work by dipping down to that java layer. Oh well no biggy. Thanks again.