4 Replies Latest reply on Nov 3, 2009 9:11 AM by Sebastian Schneider

    Conditional Task Assignment with Fork

    Pradeep Gulla Newbie

      Is it possible to assign conditional tasks with Fork node in JBPM.

      As per my requirement, workflow should allow optional Parallel tasks and a mandatory sequential task.
      But I'm getting some issues while conditionally assign tasks with fork.

      Process definition:

      <?xml version="1.0" encoding="UTF-8"?>
      <process name="conditional_task" version="1" xmlns="http://jbpm.org/4.0/jpdl">
       <start g="27,32,80,40">
       <transition to="Validate Approval Seqence"/>
       </start>
       <!-- Checks which sequence to initiate ie., Either Parallel or Sequential -->
       <decision expr="#{isOptionalTasksExists}" name="Validate Approval Seqence" g="257,31,80,40">
       <transition name="true" to="Assign Parallel Tasks" g="-24,2"/>
       <transition name="false" to="Sequential Task" g="564,54:-75,-21"/>
       </decision>
       <!-- Parallel Task Assignment -->
       <fork name="Assign Parallel Tasks" g="258,139,80,40">
       <transition to="validateFirstParallelTask"/>
       <transition to="validateSecondParallelTask"/>
       </fork>
       <!-- Conditional Task Assignment -->
       <decision name="validateFirstParallelTask" g="135,221,80,40">
       <transition to="First Parallel Task">
       <condition expr="#{firstParallelApprover != null}"/>
       </transition>
       </decision>
       <task assignee="#{firstParallelApprover}" name="First Parallel Task" g="71,325,169,40">
       <transition name="Approve" to="wait for other tasks" g="-45,-18"/>
       </task>
       <decision name="validateSecondParallelTask" g="384,221,80,40">
       <transition to="Second Parallel Task">
       <condition expr="#{secondParallelApprover != null}"/>
       </transition>
       </decision>
       <task assignee="#{secondParallelApprover}" name="Second Parallel Task" g="308,324,204,40">
       <transition name="Approve" to="wait for other tasks" g="-45,-18"/>
       </task>
       <join name="wait for other tasks" g="270,436,80,40">
       <transition to="Sequential Task"/>
       </join>
       <!-- Sequential Task -->
       <task assignee="#{sequentialApprover}" name="Sequential Task" g="494,437,147,40">
       <transition name="Approve" to="Finish" g="-45,-18"/>
       </task>
       <end name="Finish" state="Completed" g="778,431,80,40"/>
      </process>


      This definition forces me to supply either (2 Parallel and 1 Sequential) or (0 Parallel and 1 Sequential) approvers, but not 1 Parallel and 1 Sequential.

      Thanks in Advance

        • 2. Re: Conditional Task Assignment with Fork
          Joram Barrez Master

          Relax .. if you post on Sunday you shouldn't expect people to have reacted a lot by Monday ;-)

          Regarding your question: No, in jBPM you cannot model 'optional'/'mandatory' tasks in the process. However, I'm guessing you can model something alike using a decision after the task, a wait state before the join and a custom activity which triggers waiting executions. But I haven't thought this through so I could be completely wrong here ...

          • 3. Re: Conditional Task Assignment with Fork
            Pradeep Gulla Newbie

            hi,
            I've tried a different look around for this.
            viz., Assign all tasks with fork and delete unnecessary tasks with taskService.deleteTask();

            But I'm getting error like this:
            org.jbpm.api.JbpmException: tasks related to an execution must be completed. they cannot just be deleted


            Conversely javadoc suggests like this:

            /** Deletes the task without completing indicating the reason. Example reasons
            * could be: "failed", "error", "exited", "obsolete" or "deleted".
            * The history information is kept in the DB.
            * The reason ends up as the state in the {@link HistoryActivityInstance}.
            * If this task was created in the context of a process execution,
            * the execution remains active and the {@link ExecutionService#signalExecutionById(String)}
            * is to be given explicitly. */

            http://docs.jboss.com/jbpm/v4/javadocs/org/jbpm/api/TaskService.html#deleteTask(java.lang.String)

            Am I'm missing anything ??

            • 4. Re: Conditional Task Assignment with Fork
              Sebastian Schneider Master

              There is a discussion going on about this "issue" at the moment. Right now you can only complete tasks which belong to an execution and you can only delete tasks which were created independently. However if modelling an escalation from one task to a second one the first tasks remainds open and incompleted in the user's task list but it can't neither be deleted (because it belongs to an execution) nor completed because it is not active anymore.

              Join the discussion in the dev's forum and have a look at the matching JIRA issues. One idea is to introduce an additional state for tasks: cancelled