4 Replies Latest reply on May 7, 2013 10:11 AM by dmwpepper

    Passing work item results to process variables


      In my executeWorkItem method, I have


      Map<String,Object> results = new HashMap<String,Object>();

      results.put("Source_IP", "333.33.333.33");

      results.put("Start_Date", "1999 01 01");

      results.put("End_Date", "2000 01 01");



      Chapter 14 of the User Guide says:

      Result Mapping: Allows you to map a result (returned once a work item has been executed) to a variable of the process.  This allows you to use results in the remainder of the process.


      In Eclipse, there is a "Result Mapping" attribute associated with the service task.  Do I create an association between the results variable and the process variable by using the "Result Mapping" attribute?  The association seems to go in backwards.  In other words, the Parameter (work item) and Variable (process) only go in one way, so I can't put the work item result into the process variable.  I can only put the process variable into a work item result, which is the opposite of what I need to do.  So, I know I'm doing this wrong, but not sure how to do this with the Result Mapping, if that's the way its supposed to work. Thanks.

        • 1. Re: Passing work item results to process variables

          Hi David


          It looks like you and I are still walking on similar paths!


          In case you've not seen it already this may be useful JBPM5 Example -  Human Task Forms with Variables.


          Paragraph 4 suggests that output parameters need to be passed out separately and not as a map - but it was written two years ago so may be well out of date!




          Andy McC

          • 2. Re: Passing work item results to process variables

            Hey Andy, yep, the path to enlightenment gets bumpy here and there.  I didn't see this post, but did look through a number of others.  Having reviewed it, I'm still not sure what passing output parameters separately means.  Does that mean they're not captured in Eclipse/bpmn2, but instead are returned in a Java method/class?  What's the purpose of Result Mapping if it can't put the results of a task into process variables? 

            • 3. Re: Passing work item results to process variables

              Hi David,

              Did you check the Web Process Designer? That's definitely more updated than the Eclipse Plugin.

              As you mention copying variables from the work item scope to the process scope and vice versa is something vital. You need to understand that for doing that you need to have the correct mappings in the process file and then make sure that your work item is filling the variables that the process is expecting to do the copy.

              So for example let's say that you have a Process Variable called: String Customer_Name;


              At process level you should have the variable defined. In your work item you will need to define the Customer_Name variable as an input variable if you want to display or use the content of the variable (maybe another activity change its value) and as an output variable if you want to override the process variable. These mappings will be something like this:


              Customer_Name -> this is the process variable


              Now inside the WorkItem


              in_Customer_Name -> This represents the internal Work Item variable, it's not yet mapped to the process variable



              out_Customer_Name -> This represents the internal Work Item variable that will be copied back to the process, it's not yet mapped to the process variable



              Customer_Name ---(Mapped to)--> in_Customer_Name    -> This will copy the value of the process variable to the work Item in_Customer_Name when the process reach the work item node

              out_Customer_Name ---(Mapped to)--> Customer_Name   -> This will tell the process to override the process variable called Customer_Name with the value of the internal work item variable called                                                                                                        out_Customer_name.


              This mechanism is being defined by the BPMN2 language, and for that reason you need to have that in your xml file.

              Notice that your WorkItemHandler will only work with in_Customer_name and out_Customer_Name, that means that your Map<String, Object> params will need to have those keys or at least the ones defined in the dataOutputs in order to override the Process variables when you complete the WorkItemHandler.


              Hope this helps



              • 4. Re: Passing work item results to process variables

                Hey Mauricio,


                Thanks for your response.  I use Eclipse for the Java development piece, so I needed to understand how it worked in that IDE, though it will eventually be used in the Web Process Designer and JBPM Console. Your answer helps some, but I needed to understand what to do in the Java work item code.  I found a post on StackOverflow (http://stackoverflow.com/questions/9433776/jbpm-how-to-get-workitemhandler-results) that provided some hints no how to return the results in the work item so they can be used in the next service task.