cancel
Showing results for 
Search instead for 
Did you mean: 

List all service tasks

jbrazil5
Champ in-the-making
Champ in-the-making
I have tried the examples from the user guide in regards to the TaskService. The TaskService seems to only work for querying user tasks. Is there any way to list ALL the tasks(elements?) for a particular process definition(Service Tasks, Script Tasks,User Tasks)? Thank you!
3 REPLIES 3

gokceng1
Champ in-the-making
Champ in-the-making
historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).activityType(ActivityType.CALL_ACTIVITY.getValue()).unfinished().orderByExecutionId().asc();

Orders all unfinished Call_Activities of a process whose id is processInstanceId by executionId in ascending order and returns.
Hope it helps.

jbrazil5
Champ in-the-making
Champ in-the-making
Thanks for your answer! That seems to work when you have a process instance ID. I needed to know them before instantiating an instance of a process. I dug down in the api and found a way to do it. I ended up having to use their classes that represent the bpmn xml(BpmnModel). NOTE* I only did it looking for service tasks, you could do it for other things too.



BpmnModel model = repositoryService.getBpmnModel(pdef.getId());
  List<org.activiti.bpmn.model.Process> processes = model.getProcesses();
  for(org.activiti.bpmn.model.Process proc : processes) {
   listRequirements(proc);
  }


public void listRequirements(Process proc) {
  for(Object o : proc.getFlowElements()) {
   if(o instanceof ServiceTask) {
    ServiceTask st = (ServiceTask)o;
    System.out.println("Service Task : " + st.getId() + "; Name : " + st.getName() + "; Properties : " + st.getCustomProperties() + "\n============");
    for(FieldExtension fe : st.getFieldExtensions()) {
     System.out.println("Field : " + fe.getFieldName());
    }
   } else if(o instanceof SubProcess) {
    SubProcess sp = (SubProcess)o;
    listRequirements(sp);
   }
  }
}

public void listRequirements(SubProcess proc) {
  for(Object o : proc.getFlowElements()) {
   if(o instanceof ServiceTask) {
    ServiceTask st = (ServiceTask)o;
    System.out.println("Service Task : " + st.getId() + "; Name : " + st.getName() + "; Properties : " + st.getCustomProperties() + "\n============");
    for(FieldExtension fe : st.getFieldExtensions()) {
     System.out.println("Field : " + fe.getFieldName());
    }
   } else if(o instanceof SubProcess) {
    SubProcess sp = (SubProcess)o;
    listRequirements(sp);
   }
  }
}

gokceng1
Champ in-the-making
Champ in-the-making
I don't know whether it serves you but you may use ProcessParseHandler also. It lets you to intercept parsing step of process, after you upload the process definition. You may iterate through process.getFlowElements(), an check their types(userTask, endEvent, serviceTask etc.).

That may be the another way of doing this, though I didn't try.