How to get a list of tasks for a completed workflow?

I use Alfresco CE 5.2 for document management.

I have a simple parallel workflow for sending the document to review. This business process works fine.

I need to develop the dashlet, in which I need to list all the assignees and the result of reviews. Also I need to show some additional information: comments, start date, end date, on whom the task was assigned, etc.

The problem is that for the completed workflow, I can't get the task list. Here is my web script part:

model.put("workflowId", workflowId);

WorkflowTaskQuery inProgressTasksQuery = new WorkflowTaskQuery();
WorkflowTaskQuery completedTasksQuery = new WorkflowTaskQuery();

List<WorkflowTask> inProgressTasks = workflowService.queryTasks(inProgressTasksQuery, true);
model.put("inProgressTasks", inProgressTasks.size());

List<WorkflowTask> completedTasks = workflowService.queryTasks(completedTasksQuery, true);
model.put("completedTasks", completedTasks.size());

List<WorkflowTask> allWorkflowTasks = new ArrayList<WorkflowTask>();
model.put("allWorkflowTasks", allWorkflowTasks.size());

QName taskName = QName.createQName("", "registrationIncomingDocs");
WorkflowTaskQuery workflowTaskQuery = new WorkflowTaskQuery();

List<WorkflowTask> completedTasksToo = getWorkflowService().queryTasks(workflowTaskQuery);
model.put("completedTasksToo", completedTasksToo.size()); 

Open in new window

So, I get the following.

1. Active business process, one participant:

     "workflowId": activiti$11900,
     "inProgressTasks": 1, // waiting...
     "completedTasks": 1, // business process was started
     "allWorkflowTasks": 2, // total
     "completedTasksToo": 0 // ?

Open in new window

2. The same business process, but completed:

     "workflowId": activiti$11900,
     "inProgressTasks": 0,
     "completedTasks": 0, // ?
     "allWorkflowTasks": 0,
     "completedTasks2": 0 // ?

Open in new window

How to get a list of tasks for a completed workflow?

I would be very grateful for the information. Thanks to all.
Aleksey BykovAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aleksey BykovAuthor Commented:
This wonderful blog helped me:  Creating an Alfresco Task History; The Java style

Thank you, Marc!

In short:

protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) {
	Map<String, Object> model = new HashMap<>();
	String nodeRefParam = req.getParameter("nodeRefParam");
	NodeRef nodeRef = new NodeRef(nodeRefParam);
	List<WorkflowTask> allTasks = new ArrayList<>();
	List<WorkflowInstance> workflows = new ArrayList<>(); 
	workflows = workflowService.getWorkflowsForContent(nodeRef, false);
	workflows.addAll(workflowService.getWorkflowsForContent(nodeRef, true));

	if(workflows != null && workflows.size() > 0)
		for(WorkflowInstance workflowInstance : workflows) {
			WorkflowTaskQuery query = new WorkflowTaskQuery();
			List<WorkflowTask> tasks = this.workflowService.queryTasks(query);
			for(WorkflowTask task : tasks) {

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Aleksey BykovAuthor Commented:
I found the solution.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Document Management

From novice to tech pro — start learning today.