3 Replies Latest reply on Jan 18, 2008 9:07 AM by Frank

    How to retrieve the Task list of a user ?

    Frank Newbie

      Hi all !
      I have developed a web application which should be a front-end for a Jbpm process.
      In the main Servlet I should list all Task pending for a user.
      Unfortunately the task list is empty, where do I am wrong ??

      This is the simple process:

       <swimlane name="user">
       <start-state name="start">
       <transition name="" to="state1"></transition>
       <state name="state1">
       <transition name="" to="task1"></transition>
       <task-node name="task1">
       <task name="task1" swimlane="user"></task>
       <transition name="" to="end1"></transition>
       <end-state name="end1"></end-state>

      Inside the servlet I signal the process until it reaches the Task1.
      Then I expect to find one pending task for user "user". But the list is empty.

      JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
      JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
      ProcessDefinition processDefinition = ProcessDefinition.parseXmlResource("processDefinition.xml");
      ProcessInstance instance = new ProcessInstance(processDefinition);
      // Move the process instance from its start state to the state1.
      System.out.println("You are in state: "+instance.getRootToken().getNode().getName());
      // Move to Task1
      Vector vec = new Vector();
      List list = jbpmContext.getGroupTaskList(vec);
      if (list != null) {
       for (int ii=0;ii<list.size();ii++){

      Unfortunaly the List is empty.
      What is missing ? Have I assigned uncorrectly the task to "user" ??
      or Should I istantiate the Actor class and inject the "user" as userId ?

      I'm using JBoss 4.0.2 and JBPM 3.2

        • 1. Re: How to retrieve the Task list of a user ?
          Ronald van Kuijk Master

          actor class is not needed. Please make a unit test that demonstrates the problem....

          • 2. Re: How to retrieve the Task list of a user ?
            David Roberts Apprentice

            In your process definition, you have:

            <swimlane name="user">

            You've defined a swimlane called "user", but you haven't assigned any users to that swimlane.

            Also, to get a list of tasks that can potentially be assigned to a user, I use a method like this:
             * Gets all task instances that a user with the given actor id could claim.
             * @return List of jbpm task instances.
             public static List getUnClaimedTaskInstancesForActorId (JbpmContext jbpmContext, String actorId) {
             Session session = jbpmContext.getSession();
             //create list of possible id's (this includes groups) that
             //belong to the current user.
             List actorsList = new ArrayList();
             IdentitySession identitySession = new IdentitySession(session);
             org.jbpm.identity.User jbpmUser = identitySession.getUserByName(actorId);
             Iterator i = jbpmUser.getMemberships().iterator();
             Membership m = (Membership) i.next();
             List pooledTaskInstances = jbpmContext.getTaskMgmtSession().findPooledTaskInstances(actorsList);
             List jbpmTaskInstanceList = session.createQuery("from org.jbpm.taskmgmt.exe.TaskInstance ti where ti.start is null and ti.end is null and actorId = '"+actorId+"'").list();
             //add pooledTaskInstances to taskList
             //TODO sort jbpmTaskInstanceList by task instance id
             return jbpmTaskInstanceList;

            Hope this helps a bit. Good luck!

            • 3. Re: How to retrieve the Task list of a user ?
              Frank Newbie

              Thanks for your kind replies.
              At the moment I have solved the problem using an assignment handler which fires when the Task node is entered.
              Thanks for your hints.