cancel
Showing results for 
Search instead for 
Did you mean: 

Multi instance User Task

demotdi
Champ in-the-making
Champ in-the-making
I am in the process of migrating JBPM4 processes to Activiti.

<foreach in="#{users}" name="users" var="user">
      <transition to="approve"/>
</foreach>
<task name="approve">
  <transition name="Work Complete" to="Review"/>
</task>
<task name="Review">
</task>

The above foreach construct in JBPM4 transitions to an user task. If the size of users is 2, it creates two tasks.

Can this be done in Activiti without using a subprocess? When user 1 completes 'approve' task, I would like to create the 'Review' task.  I am not able to make it work with multi instance user or service task as the task count shows 1 and not 2 ("approve task for user 2" and "Review task for user 1")

I would appreciate your help. Thank You.
2 REPLIES 2

yz250
Champ in-the-making
Champ in-the-making
Well, if you want to create a multi instance task (user or service doesn' t matter) you have to click on the task, select "multi instance" label, then set Collection=yourcollectionname and Element variable=assignee, in the "main config" label you have to set Assignee=${assignee}.
To create your collection you have to add a service task that point a java class and in the java class you have to write:

import java.util.ArrayList;
import org.activiti.engine.delegate.*;
public class multi implements JavaDelegate{
  public void execute(DelegateExecution execution) throws Exception {
      ArrayList<String> nameList = new ArrayList<String>();          
      nameList.add("user1");
      nameList.add("user2");
      nameList.add("user3");
      execution.setVariableLocal("nameList", nameList);
  }
}

Now you have created the collection, so click on your folder project then "Create deplyoment artifacts" so in your deployment folder you will now have the file "myclass.jar", copy that file in your activiti folder under apps/tomcat/activiti-explorer/WEB-INF/libs the restart it with "ant demo.stop" then "ant demo.start".
This is for eclipse designer, i don' t know how to make it with other designers.

Cheers, Ivan.

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
You can also do this by just setting a process variable via the api. Does not need to be a service task, or via an expression that returns this list.