3 Replies Latest reply on May 5, 2010 5:32 AM by newbeewan

    find User tasks

    newbeewan

      Hi,

       

      I'm trying to find some tasks assign to a user, but no success !

       

      I have done a mock identity service to produce test data

       

      My test process :

      <?xml version="1.0" encoding="UTF-8"?>
      
      <process key="test" name="userTaskTest" version="1" xmlns="http://jbpm.org/4.0/jpdl">
          <start candidate-users="john" g="0,0,80,40" name="init">
            <transition to="johnTask" g="-93,-24"/>
          </start>
      
          <end g="258,238,80,40" name="theEnd"/>
         <task candidate-users="sarah" g="170,179,92,52" name="sarahTask">
            <transition g="-81,-24" name="to theEnd" to="theEnd"/>
         </task>
         <task candidate-users="john" g="46,65,92,52" name="johnTask">
            <transition g="-110,-24" name="to SarahTask" to="sarahTask"/>
         </task>
      </process>

       

       

      My test :

       

      RepositoryService repositoryService = processEngine.getRepositoryService();
      ProcessDefinition testProcess = repositoryService.createProcessDefinitionQuery()
                      .processDefinitionKey("test").uniqueResult();
      ExecutionService executionService = processEngine.getExecutionService();
      ProcessInstance instance = executionService.startProcessInstanceByKey("test");
      logger.info("instance state : {}", instance.getState());
      Set<String> activities = instance.findActiveActivityNames();
      for (String activity : activities) {
              logger.info("Activity : {}", activity);
      }
      
      TaskService taskService = processEngine.getTaskService();
      
      List<Task> tasks = taskService.findPersonalTasks("john");
      assertFalse("No tasks for John !", tasks.isEmpty());
      

       

      No tasks for john !

      Expected 1 because of candidate-users="john" in the task "johnTask", am I wrong ?

       

      How to make it works ?

       

      Thanks

        • 1. Re: find User tasks
          rebody

          Hi Jaber,

           

            If you used candidate-users or candidate-groups to set the participants of a Task.  You should use taskService.findGroupTask("John") to get the group task list.

          • 2. Re: find User tasks
            zecas

            Hi,

             

            You have defined the users as candidate-users="...", and that makes the tasks available on the group task list. For a user to list, you must call:

             

             

            tasks = taskService.findGroupTasks("john");
            

             

            Then if you want to work with it, you must pick it up, so the task is given a specific assignee, and no other person picks it up:

             

             

            taskService.takeTask(tasks.get(0).getId(), "john");
            

             

            You must work out the tasks.get(0).getId() part

             

             

            Edit: you can find more info on sub-section 6.2.6.2. task  candidates here: http://docs.jboss.com/jbpm/v4/userguide/html_single/#task

             

             

            Hope it helps.

            • 3. Re: find User tasks
              newbeewan

              Ok, I was melting candidate and assignee

               

              I have also found a workaround with :

               

              taskService.createTaskQuery().candidate("john").list();

               

              Thanks for your replies !