Retrieving all tasks for content (solved and described)

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
kwantm
Active Member

Retrieving all tasks for content (solved and described)

hi,

I am trying to code a custom method in the WorkflowBean to retrieve all tasts for content.

I have read the following post http://forums.alfresco.com/viewtopic.php?p=25854&sid=0bd633e1bc22551db79be683592522f6  on this, but I have a question on this.

what does the processId mean. is this the WorkflowInstance.id ??

=======

furthermore I can see in my custom code that an inactive    workflowinstance is found but the workflowService.querytask method cannot find the task associated with the workflowinstance.

I have added my custom method below.


   public List<Node> getAllTasks() {
      // get the current username
//      FacesContext context = FacesContext.getCurrentInstance();
//      User user = Application.getCurrentUser(context);
//      String userName = user.getUserName();
//
//      UserTransaction tx = null;
//      try {
//         tx = Repository.getUserTransaction(context, true);
//         tx.begin();

         this.allTasks = new ArrayList<Node>();
         List<WorkflowInstance> workflows = new ArrayList<WorkflowInstance>();
         workflows = workflowService.getWorkflowsForContent(
               documentDetailsBean.getDocument().getNodeRef(), false);
         workflows.addAll(workflowService.getWorkflowsForContent(
               documentDetailsBean.getDocument().getNodeRef(), true));

         if (workflows != null && workflows.size() > 0) {
            for (WorkflowInstance wi : workflows) {
               WorkflowTaskQuery query = new WorkflowTaskQuery();
               //query.setTaskState(WorkflowTaskState.COMPLETED);
               
               query.setProcessId(wi.id);
               List<WorkflowTask> tasks = this.workflowService.queryTasks(query);

                  // create a list of transient nodes to represents
                  for (WorkflowTask task : tasks)
                  {
                     Node node = createTask(task);
                     this.allTasks.add(node);
                    
                     if (logger.isDebugEnabled())
                        logger.debug("Added task: " + node);
                  }
            
            }
         }
         // commit the changes
//         tx.commit();
//      } catch (Throwable e) {
//         // rollback the transaction
//         try {
//            if (tx != null) {
//               tx.rollback();
//            }
//         } catch (Exception ex) {
//         }
//         Utils.addErrorMessage("Failed to get all tasks: "
//               + e.toString(), e);
//      }
      return this.allTasks;
   }

I have tried with or withour user context, with the workflowtask setting etc…

But Iam not getting the completed tasks on my screen.

Does anyone have any idears on how this can be done, or more importantly, what am I doing wrong?

regards,

Marc
http://www.wowww.nl
6 Replies
davidc
Active Member II

Re: Retrieving all tasks for content (solved and described)

By default, a task state of COMPLETED is queried.

If you want to search ignoring task state (i.e. complete and in progress), then use…

query.setTaskState(null);
kwantm
Active Member

Re: Retrieving all tasks for content (solved and described)

Hi,

Thanks for your information. Unfortunately this does not give me the output I was hoping for.

The completed tasks/workflows still disappear from my task list. What I can see during debugging in Eclipse, is that the code does find the completed workflow (with active==false) but when the the following section of code is executed:

WorkflowTaskQuery query = new WorkflowTaskQuery();
               query.setTaskState(null);
               query.setProcessId(wi.id);
               List<WorkflowTask> tasks = this.workflowService.queryTasks(query);

it does not find the tasks that are part of the completed workflow.
Because of this I was wondering if either Iam using the wrong processId or that the query behind this code doesn't work like i think it works.

My questions is: If I know the WorkflowInstance, can i get the completed tasks of it with my code using the workflowinstance.id as processid???

Kind regards,

Marc
http://www.wowww.nl
kwantm
Active Member

Re: Retrieving all tasks for content (solved and described)

hi,

I have solved my isssue. I compared my code against the task history in the task-manage page and came to the conclusion that I was missing the following piece of code:


query.setActive(wi.active);

When this is added, the view presents me with the completed tasks as well.

Kind regards,

Marc
http://www.wowww.nl
kwantm
Active Member

Re: Retrieving all tasks for content (solved and described)

I have written a small article on this functionality. Anyone who whats this, can get the info here

http://www.wowww.nl/wordpress/?p=69

Kind regards,

Marc
http://www.wowww.nl
davidc
Active Member II

Re: Retrieving all tasks for content (solved and described)

Excellent.
alekseybykov
Established Member II

Re: Retrieving all tasks for content (solved and described)

Thank you, Marc!

Regards.