4 Replies Latest reply on Aug 17, 2010 1:06 PM by matrixpooh

    Getting the last actor of the completed task

    matrixpooh

      How can I get the last task assignee of the completed task from the history tables having execution id and activity Name?

        • 1. Re: Getting the last actor of the completed task
          swiderski.maciej

          Hi,

           

          in general you can do it using TaskService and TaskQuery, as follows:

           

          List<Task> tasks = taskService.createTaskQuery().
                         processInstanceId(processInstance.getId()).activityName("activityName").list();
          

          You can use as well orderByDesc or Asc to sort the result.

           

          HTH

          Maciej

          • 2. Re: Getting the last actor of the completed task
            swiderski.maciej

            Hi,

             

            sorry, I gave you wrong examples. It should be:

             

            List<HistoryTask> history = historyService.createHistoryTaskQuery().executionId(processInstance.getId()).list();
            

             

            Unfortunately there is no way to narrow down the search by activity name but you can either use task id or outcome.

             

            In the worst case you will get all completed task for execution and the filter it manually.

             

            Cheers,

            Maciej

            • 3. Re: Getting the last actor of the completed task
              matrixpooh

              Thanks Maceij,

               

              I went with a work-around:

               

              I made transitions to the tasks match tasks names: if a task is called 'task-1', then transition is 'to-task-1'. Holding the pattern, i can do:

               

              processEngine.getHistoryService().createHistoryTaskQuery().executionId(executionId+".to-"+activityName).state(Task.STATE_COMPLETED).uniqueResult();

              where activityName is 'task-1'

               

              Thanks again for help!

              • 4. Re: Getting the last actor of the completed task
                matrixpooh

                Found a better way to get a history task via HistoryActivityInstance:

                 

                HistoryActivityInstance hai = historyService.createHistoryActivityInstanceQuery().processInstanceId(pid).activityName(activityName).uniqueResult();

                if (hai.getClass() == HistoryTaskInstanceImpl.class)

                     HistoryTask ht = ((HistoryTask)hai).getHistoryTask();