cancel
Showing results for 
Search instead for 
Did you mean: 

How can I get all workflow tasks?

vergude
Champ in-the-making
Champ in-the-making
Hello!

I have such code:

public class CompleteWorkflow extends Workflow{
   
   
    public List<WorkflowTaskItem> getCreatedCompletedTasks()
    {
              
       WorkflowTaskQuery workflowTaskQuery = new WorkflowTaskQuery();
       workflowTaskQuery.setTaskState(WorkflowTaskState.COMPLETED);
       
        List<WorkflowTask> tasks = getWorkflowService().queryTasks(workflowTaskQuery);
       
        return convertTasks(tasks);
    }
   
    /**
     * Convert a list of WorkflowTask items into bean objects accessable from templates
     *
     * @param tasks     List of WorkflowTask objects to convert
     *
     * @return List of WorkflowTaskItem bean wrapper objects
     */
    private List<WorkflowTaskItem> convertTasks(List<WorkflowTask> tasks)
    {
        List<WorkflowTaskItem> items = new ArrayList<WorkflowTaskItem>(tasks.size());
        for (WorkflowTask task : tasks)
        {
            items.add(new WorkflowTaskItem(this.services, getTemplateImageResolver(), task));
        }
       
        return items;
    }

    private WorkflowService getWorkflowService()
    {
        return this.services.getWorkflowService();
    }
   
   
}


But this code doesn`t work correctly. I want to get all completed task for all users.

There is method 
public List<WorkflowTaskItem> getCompletedTasks()
  In Workflow.java.
This method Return a list of objects representing the completed tasks for the current user/
But I need to get completed task for all users.

Please, help me! (Sorry, I speak English not very well, but I understand).
3 REPLIES 3

vinaxwater
Champ in-the-making
Champ in-the-making
Dear vergude,

Code for get All Task:

WorkflowTaskQuery query = new WorkflowTaskQuery();
query.setTaskState(WorkflowTaskState.COMPLETED);

List<WorkflowTask> result = this.workflowService.queryTasks(query);

Regards
vinaxwater

lucille_arkenst
Champ in-the-making
Champ in-the-making
Dear vergude,

I see you are doing what vinaxwater suggests already:

      WorkflowTaskQuery workflowTaskQuery = new WorkflowTaskQuery();
      workflowTaskQuery.setTaskState(WorkflowTaskState.COMPLETED);

      List<WorkflowTask> tasks = getWorkflowService().queryTasks(
            workflowTaskQuery);
The getWorkflowService() is the new way; they don't have workflowService instance variable in Workflow class anymore.

I am thinking maybe the problem lies wherever you call this.services:

         items.add(new WorkflowTaskItem(this.services,
               getTemplateImageResolver(), task));
etc…

      return this.services.getWorkflowService();
You can't access Workflow.services; it's just getWorkflowService()

Have a look at this page: http://www.wowww.nl/wordpress/2007/09/14/creating-an-alfresco-task-history-the-java-style/… Marc has a nice explanation; although I believe he is using the old-style coding too.  But you can see what he is doing if my suggestion doesn't work for you Smiley Very Happy

vergude
Champ in-the-making
Champ in-the-making
Thanks for answers.

This is my code. It works and I can see all completed tasks.

QName taskName = QName.createQName("http://www.alfresco.org/model/workflow/1.0", "adhocTask");
       
       // get all "completed" adhoc Tasks
       WorkflowTaskQuery workflowTaskQuery = new WorkflowTaskQuery();
       workflowTaskQuery.setActive(null);//this is very important
       workflowTaskQuery.setTaskName(taskName);
       workflowTaskQuery.setTaskState(WorkflowTaskState.COMPLETED);
       
        List<WorkflowTask> completedTasks = getWorkflowService().queryTasks(workflowTaskQuery);