Difference between revisions of "Use of task node"

From OpenKM Documentation
Jump to: navigation, search
(Swimlane sample use)
m (Swimlane sample use)
 
(One intermediate revision by the same user not shown)
Line 63: Line 63:
 
</start-state>
 
</start-state>
 
</source>
 
</source>
 +
 +
You can also access the user assigned to a swimlane from Java code. In this sample code we'are looking for the swimlane "initiator":
 +
 +
<source lang="java">
 +
ProcessDefinition procDef = execContext.getProcessDefinition();
 +
TaskMgmtDefinition taskMgmtDef = procDef.getTaskMgmtDefinition();
 +
TaskMgmtInstance taskMgmtIns = execContext.getTaskMgmtInstance();
 +
Swimlane swimlane = taskMgmtDef.getSwimlane("initiator");
 +
SwimlaneInstance swimlaneIns = taskMgmtIns.getInitializedSwimlaneInstance(execContext, swimlane);
 +
String actorId = swimlaneIns.getActorId();
 +
</source>
 +
 +
You can use this code in a ActionHandler to do something related to a given swimlane.
  
 
== Mail notification ==
 
== Mail notification ==

Latest revision as of 10:33, 17 August 2013

Now we are going to see how you can create task in jBPM and assign them to actors who will perfom the task. Actors also can select a pending task and assign to himself.


Nota clasica.png Source Eclipse project at File:Workflow samples.zip.

First of let's create a process definition called "task" with an initial node, a task node and a end node:

Jbpm sample task.png

As seen previously, a task node represents one or many tasks executed by a human person. When the process execution arrives to a task node, an task instance is created in the workflow member list. This node will enter in a wait state until the user notify the conclusion of the task.

In order to create a task in a task node, go to the properties of this node. In the tasks table click on the right mouse button and select New Task. Give a name to this task, for example "something_to_do" and a optional description. In the Assignment tab we can see different ways to assign a task:

  • Actor: Here we put the actorId. This is a String which identify the actor who will perform the task. When the process flow enters in the task node, the task is created and is added to the list of this actor's pending task.
  • Pooled Actor: A sequence of actorId separated by commas. When this task is created is not assigned to any actor. An actor should get it from the list of pooled tasks. Once the actor get the task, it is added to his own list of pending tasks.
  • Swimlane: A swimlane defines an assignment which is the same for several tasks in a process.
  • Expression: This is an assignment expression evaluated by the jBPM identity component. Can make assignment by user or role (See note below). For example you can assign userd from a OpenKM role using the "group(ROLE_USER)" expression. This create a collection of pooled actors with using whithin ROLE_USER role.

Nota clasica.png You can see a complete task example with swimlanes in File:Wf-revision.zip.

In this case we are going to assign the task to an user called "yoda":

<?xml version="1.0" encoding="UTF-8"?>
<process-definition xmlns="urn:jbpm.org:jpdl-3.2" name="task node">
    <start-state name="start">
        <transition to="task"></transition>
    </start-state>

    <task-node name="task">
        <task name="something_to_do">
            <assignment actor-id="yoda"></assignment>
        </task>
        <transition to="end"></transition>
    </task-node>

    <end-state name="end"></end-state>
</process-definition>

But changing task assignment from the graphical editor is more simple. Let's see this sample workflow with a task node called "HR" which have a task called "HR Assign". These are the steps to change the task assignment:

Jbpm node task assignment.png
  1. Select the task node
  2. Click on the properties tab
  3. Click on the task section
  4. Select the Assignment tab. Here you can select between several ways of assignment. The most simple is the Actor, which is mapped with an OpenKM user.

Swimlane sample use

Many times we need to assign a task to the user who started the workflow. This can be done using swimlanes. Tipically this star user is assigned to the swimlane initiator, but is not done automatically. You need to add this swimlane to the process definition and assign in the start task:

<swimlane name="initiator"></swimlane>

<start-state name="start">
	<task swimlane="initiator"></task>
	<transition to="Next Node"></transition>
</start-state>

You can also access the user assigned to a swimlane from Java code. In this sample code we'are looking for the swimlane "initiator":

ProcessDefinition procDef = execContext.getProcessDefinition();
TaskMgmtDefinition taskMgmtDef = procDef.getTaskMgmtDefinition();
TaskMgmtInstance taskMgmtIns = execContext.getTaskMgmtInstance();
Swimlane swimlane = taskMgmtDef.getSwimlane("initiator");
SwimlaneInstance swimlaneIns = taskMgmtIns.getInitializedSwimlaneInstance(execContext, swimlane);
String actorId = swimlaneIns.getActorId();

You can use this code in a ActionHandler to do something related to a given swimlane.

Mail notification

A notification email can be send when a task gets assigned to an actor. Just use the notify="yes" attribute on a task like this:

<task-node name="task">
    <task name="something_to_do" notify="yes">
        <assignment actor-id="yoda"></assignment>
    </task>
    <transition to="end"></transition>
</task-node>

Setting notify to "yes", "true" or "on" will cause jBPM to send an email to the actor that will be assigned to this task. The email is based on a template (see JBPM3 mail configuration) and contains a link to the related document in the web application.

Similarly as with assignments, emails can be send as a task reminder. The reminder element in jPDL is based upon the timer. The most common attributes will be the duedate and the repeat. The only difference is that no action has to be specified.

<task-node name="task">
    <task name="something_to_do" notify="yes">
        <assignment actor-id="yoda"></assignment>
        <reminder duedate="2 business days" repeat="2 business hours"/>
    </task>
    <transition to="end"></transition>
</task-node>

Nota clasica.png Since OpenKM Community 6.2.2 and OpenKM Professional 6.2.7 you can use assigment expressions. Read Task management: Assignment expressions for more info.