2 Replies Latest reply on Dec 13, 2006 5:04 AM by Alberto Martinez

    Taks instances

    Alberto Martinez Newbie


      I am trying to create a Task instances list with the pendings tasks for an actor. I am not doing it from a JSF, so I think that I can't use TaskIntanceList or TaskInstaceListFoType components.

      Following DVD Store example, I think that I must use ManagedJbpmContext.

      This is the process definition:

      <start-state name="Inicio">
       <transition name="peticion" to="Peticion"></transition>
       <task-node name="Peticion">
       <task name="evaluarPeticion">
       <assignment actor-id="#{asignarTarea.getBibliotecario}"/>
       <transition name="aceptar" to="Pedido"></transition>
       <transition name="cancelar" to="Eliminado"></transition>

      I would like to get a tasks list for type "evaluarPeticion" from a bean method.

      At this momments, it is working with this code:

      public void test() {
       AsignarTarea bibliotecario = new AsignarTarea();
       // JBPM Context
       JbpmContext context = ManagedJbpmContext.instance();
       // Taks for an actor
       TaskMgmtSession tms = context.getTaskMgmtSession();
       List<TaskInstance> taskInstances = (List<TaskInstance>) tms
       // Task filter
       for (Iterator<TaskInstance> itr=taskInstances.iterator(); itr.hasNext();) {
       TaskInstance taskInstance = itr.next();
       if (taskInstance.getName().equals("evaluarPeticion"))

      With this method I get all the information I am looking for and it is working fine, but I think that this is not the best way to do it.

      Looking at the DVD Store demo, it uses the context.getSession to create a query and access to the information. Can I do somethig like that to get a task instances list for an actor and for a type without manually iterate all the task instances?

      If I use context.getSession, I dont know how to implement a query to retrieve a task list.


        • 1. Re: Taks instances
          Pete Muir Master


          @In List<TaskInstance> taskInstanceList;
          is valid.

          And of course you could @In JbpmContext;

          • 2. Re: Taks instances
            Alberto Martinez Newbie


            "petemuir" wrote:
            @In List<TaskInstance> taskInstanceList;
            is valid.

            And of course you could @In JbpmContext;

            Ok, it works fine... thank you.

            I had it working now with this query:

            List<TaskInstance> ti = (List<TaskInstance>) context.getSession()
             .createQuery("select ti from org.jbpm.taskmgmt.exe.TaskInstance as ti where ti.actorId = :actorId and ti.end is null and ti.isCancelled = false and ti.name = :taskName")
             .setString("actorId", bibliotecario.getBibliotecario())
             .setString("taskName", "evaluarPeticion").list();

            but i prefer your solution, injecting the taskInstanceList is just what I need.

            Thanks again.