AnsweredAssumed Answered

Retrieving all tasks for content (solved and described)

Question asked by kwantm on Sep 10, 2007
Latest reply on Jun 26, 2018 by Aleksey Bykov
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

Outcomes