cancel
Showing results for 
Search instead for 
Did you mean: 

Get all user tasks for a process definition/instance

viralparekh
Champ in-the-making
Champ in-the-making
I have a simple requirement - I need to get all user tasks for a given process. Using taskservice or historyservice only gives me active or completed tasks. How do I get all the tasks in a process? I have found the below code from some earlier forum threads. Is this acceptable? I believe there should be a better public API than this.


ProcessDefinitionEntity processDefinition =
            (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(processInstance.getProcessDefinitionId());

        if (processDefinition != null) {
            for (ActivityImpl activity : processDefinition.getActivities()) {
              String type = (String) activity.getProperty("type");
              String name = (String) activity.getProperty("name");
              String taskId = activity.getId();

              System.out.println("type: "+type+" name: "+name + " id: " + taskId);

            }
        }
3 REPLIES 3

iam
Champ in-the-making
Champ in-the-making
You can get task definitions from process definition:
[java]
Map<String, TaskDefinition> taskDefinitions = processDefinition.getTaskDefinitions();
[/java]
After that if you need ActivityImpl you can find it by key from process definition:
[java]
ActivityImpl activity = processDefinition.findActivity(activityId);
[/java]

viralparekh
Champ in-the-making
Champ in-the-making
Isn't there a public api or rest api to a get all the tasks of a given process?

jbarrez
Star Contributor
Star Contributor
Use the repositoryService.getBpmnModel method. It will give you a Java pojo version of your process definition