cancel
Showing results for 
Search instead for 
Did you mean: 

Get all user tasks' names in one long process

lingnan
Champ in-the-making
Champ in-the-making
Hi, I'm a beginner using Activiti. In my BPMN project, I have a really long line like this:

start -> usertask1 ->usertask3 ->usertask4->usertask5 -> … ->usertask 15 ->end     (task1 and task2 are paralleled)
        -> usertask2 ->
I want to get all the usertasks' names or I want to get usetask15's id and name. What I do now is

         TaskService taskService = activitiRule.getTaskService();
       List<Task> tasks = taskService.createTaskQuery().taskAssignee("kermit").list();
      
      for (Task task : tasks){
         System.out.println("Task available: " + task.getName());
         taskService.complete(task.getId());
      }
      
      Task task = taskService.createTaskQuery().taskAssignee("kermit").singleResult();
       System.out.println("name " + task.getName());

OUTPUT: Task available: usertask1
Task available: usertask2
name usertask3

Using this method, I can only get usertask3 and if I want to get usertask15, I have to write lots of complete and taskService. Is there any quick way for me to get all the usertasks' name at the same time? Thank you very much!!
3 REPLIES 3

trademak
Star Contributor
Star Contributor
Hi,

If you are only interested in the user task names it's best to get the BpmnModel via the RepositoryService. In the BpmnModel you can get all user tasks defined in the BPMN XML.

Best regards,

lingnan
Champ in-the-making
Champ in-the-making
Thank you for your quick reply!
Do you have any sample code about getting ids and names from XML?

jbarrez
Star Contributor
Star Contributor
What do you mean? The id and name are simply getters on the objects inside the BpmnModel