RSS

Using Variables in JBPM5 Human Tasks

06 May

I have been playing a bit with processes and human tasks, and I want to show how we can share variables between human tasks in Jbpm5.

Let’s see the following process:

There are three human tasks which may have input/output:

  • Write document: Should produce an output that should contain a document which will be used by the rest of the process.
  • Translate Document: Should take the “Write document” output to show to the user for reference, and produce an output that will contain the translated document.
  • Review Document: Should take the “Write document” output to show to the user for reference, and produce an output that will contain the review of this document.
First, let’s deal with the write document output.
In the .bpmn file, we will add a new item definition, which will define the structure and a name for this structure, and  then declare a variable inside our process:
Ok, now we should define the variable inside the “Write document” task, and bind it with this process property:
Results will be the name of the variable inside the task.
– In dataOutputAssociation we put the value of the Results to the approval.document variable.
Now, let’s use this variable as an input of “Translate Document”. We will use the already filled approval.document variable, and declare it as a parameter for the task.
Please note for the input variable, I used “Content” name variable. If you see the workitem for human tasks in jbpm5, its takes some predefined parameters and sends them to the task server, so the input information should be put in Content input. Edit: after a salaboy commit some time ago, now, the input of the task will be get from the “content” variable. If you want to send many separate variables, you can omit (send it blank) the content variable, and add other variables. If the human task work item handler  does not find anything in content variable, it will send a map with all the task variables as input.
The complete process definition can be found here:
Now, how can I use it from my human task?
To get the input, using the TaskClient and having the TaskSummary is possible:
To send the output:
The full example can be found in my examples github repository:
That’s all for now. Hope it helps.
Thanks for reading!
Demian
Advertisements
 
5 Comments

Posted by on May 6, 2011 in Drools, JBPM

 

Tags: , ,

5 responses to “Using Variables in JBPM5 Human Tasks

  1. salaboy

    May 9, 2011 at 3:44 am

    This post is excellent.. very useful.. We can create a set of posts describing each service task structure.. and we should add this material to the community training courses!

     
  2. calcacuervo

    May 11, 2011 at 8:02 pm

    That is good idea salaboy. I’ll put hands on next service tasks posts, and we definitely can add it the the community training courses.

    Thanks!

    Demian

     
  3. Marie

    June 2, 2011 at 7:31 am

    As I understand it, the variables are passed between tasks with WorkItem:
    line 300 in
    WSHumanTaskHandler
    session.getWorkItemManager().completeWorkItem(task.getTaskData().getWorkItemId(), results);

    When using persistence of process variables, in table VARIABLEINSTANCELOG, the variable has to be String (VARCHAR2(255 CHAR)). Objects are saved as .toString().

    Therefore, having in Structure definition of variables anything else than String (or types which can be converted to String without information lost, eg. Integer) does not have much use.
    Do you have any trick for storing objects generally?

     
  4. calcacuervo

    June 14, 2011 at 3:08 am

    Hi Marie, I am back in the blog, sorry for the delay.

    I think what you can do is marshall separatetly your processes variables and store them in an external data source.
    This test should help you:
    https://github.com/droolsjbpm/jbpm/blob/master/jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/session/VariablePersistenceStrategyTest.java
    Please let me know if it helps,
    Demian

     
  5. Marie

    June 22, 2011 at 11:53 am

    Hi, thank you. Based on your input, I started thinking and thinking about the test you send and variables, and I got it.
    I was always thinking that the process variables are taken from VARIABLEINSTANCELOG. But this is just log, the objects used in process run are in PROCESSINSTANCEINFO in blob column.

    My previous question is therefore irrelevant.
    Thank you again.

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: