4 Replies Latest reply on Nov 2, 2008 6:26 AM by Paolo Garrone

    Task nodes problem

    Paolo Garrone Newbie

      Hello,

      I'm an italian developer approaching jBPM with NetBeans+GlassFish, and I'm encountering some problems in managing tasks and task nodes: I've created a process definition with a start-state, two task nodes (separated by a simple state I only use to check che flow) and a transition between the two (so I defined the tasks in the processdefinition.xml file). I was trying to get from the first task to the second by completing them, but I don't understand very well how to use the task management stuff.

      I read that to obtain a task instance you have to call:

      TaskInstance taskInstance = (TaskInstance) processInstance.getTaskMgmtInstance().getTaskInstances().iterator().next();
      

      where "processInstance" is a process instance created from a process definition etc; but how must I do if I have more than one task?

        • 1. Re: Task nodes problem
          Mauricio Salatino Master

          If you know a little about Java, you should look the jBPM API and notice that

          processInstance.getTaskMgmtInstance().getTaskInstances()
          

          Give you the list (List) of all the task that you have at some moment.

          Hope it helps

          • 2. Re: Task nodes problem
            Ronald van Kuijk Master

            And this is only for one taskinstance. If you want it for all taskinstances, use the JbpmContext api

            • 3. Re: Task nodes problem
              Paolo Garrone Newbie

               

              "kukeltje" wrote:
              And this is only for one taskinstance. If you want it for all taskinstances, use the JbpmContext api

              Can you give me an example please?

              • 4. Re: Task nodes problem
                Paolo Garrone Newbie

                Ok, no problem: I think I just solved the matter following a simple example I found browsing the net; the example manages different tasks by creating different task instances:

                Token token = processInstance.getRootToken();
                
                <some code that brings the process to task-node 1>
                
                TaskInstance t1 = (TaskInstance) processInstance.getTaskMgmtInstance().getTaskInstances().iterator().next();
                t1.start();
                 out.println("some feedback for task 1");
                t1.end("task2");
                
                token.signal();
                
                TaskInstance t2 = (TaskInstance) processInstance.getTaskMgmtInstance().getUnfinishedTasks(token).iterator().next();
                t2.start();
                out.println("some fedback for task 2");
                t2.end("end state");
                


                I did not use the "getUnfinishedTasks(token)" function, now it seems to work: I assign actor to the task in a java class implementing AssignmentHandler.

                If you don't mind, I have another question: on jBPM online documentation, cap 12 ("task management") I read that "Tasks can be defined in task-nodes and in the process-definition"; now I defined my task in the processdefinition.xml file:

                <task-node name="task1">
                 <task name="task1">
                 <assignment class="task1HandlerClass" />
                 </task>
                 <transition name="follow" to="state2" />
                </task-node>
                


                ...but what about if I want to define tasks following another way? The docs say that "task instance creation might be based upon a runtime calculation. In that case, add an ActionHandler on the nodeenter event of the task-node and set the attribute create-tasks=false."; so, I guess something like:

                <task-node name="task1" create-tasks="false">
                 <event type="node-enter">
                 <action class="createTask1" name="task1" />
                 </event>
                </task-node>
                


                Getting to the point, what is the meaning of the "create-tasks=false" attribute? And, how can I assign the handler to a task created in such way? Do I simply introduce an in the task node, as above?

                Thanks...