cancel
Showing results for 
Search instead for 
Did you mean: 

Java Service Task Problem with List

smee82
Champ in-the-making
Champ in-the-making
Hello,
i want to set List of users (productmanagers) as a variable. I want to reuse this variable for a multiinstance task which needs a collection. The collection should contain these users. I tried different possibilities but only get Exception:couldn't instantiate class. Does anybody know how to store a list as a process variable so i can use it as a collection in a multi-instance task?

Thank for your help!


public class IdentifyMembers implements JavaDelegate {

   @Override
   public void execute(DelegateExecution execution) {
      System.out.println("SERVICE");
      String[] str_memberList = {"geschaeftsfuehrer", "controller", "hbl_it", "hbl_2", "prod_man_1", "prod_man_2", "auftraggeber_1"};
      String[] str_productmanagerList = {"prod_man_1", "prod_man_2"};
      List<String> productmanagerList = Arrays.asList(str_productmanagerList);
      
                //first try
      execution.setVariable("productmanagerList",  CollectionUtil.singletonMap("productmanagerList", productmanagerList));
      
      //second try
      //Map<String, Object> map = new HashMap<String, Object>();
       //map.put("productmanagerList", productmanagerList);
       //execution.setVariable("productmanagerList", map);
   }   
}
3 REPLIES 3

gant
Champ in-the-making
Champ in-the-making
I think, List is only an interface and thus can't be instantiated. Use ArrayList or something instead.
regards

smee82
Champ in-the-making
Champ in-the-making
I did this before and it works to store my list:

public class MyJavaService implements JavaDelegate {

@Override
public void execute(DelegateExecution execution) {
  System.out.println("SERVICE");
  String[] str_assigneeList = {"kermit", "gonzo", "fozzie"};
  execution.setVariable("assigneeList",  str_assigneeList);
}
}

But the problem is that i cannot use this "assigneeList" as a collection in the multi-instance task. Thats the main issue. The following example works when i start a new process instance and i can use the "assigneeList" in my multi-instance task. But i want so set the variables in Java ServiceTask.

  String[] str_assigneeList = {"kermit", "gonzo", "fozzie"};
  List<String> assigneeList = Arrays.asList(str_assigneeList);
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("MultiInstanceTask", CollectionUtil.singletonMap("assigneeList", assigneeList));
  System.out.println("Started Process instance id " +processInstance.getProcessInstanceId());

smee82
Champ in-the-making
Champ in-the-making
String[] str_productmanagerList = {"prod_man_1", "prod_man_2"};
Collection<String> productmanagerList = Arrays.asList(str_productmanagerList);
execution.setVariable("productmanagerList",  productmanagerList);

I finally got it. It works with Collection.