6 Replies Latest reply on Sep 7, 2011 4:24 AM by Darryl Youngblood

    passing data to nodes

    Darryl Youngblood Newbie

      Hey guys,

       

      I'm not sure if I got it right. So far i believe there are two ways to pass information to other nodes.

       

      1. In the executeWorkItem method of a custom workItemHandler class I can put information in a map and use WorkItemManager.completeWorkItem(workItemId, Map<String, Object>); to pass the information to the next node.

       

      2. I could use globals to store information inside

       

      Is this right or am I wrong?

       

      The problems I encounter are:

       

      1. I don't know how to retrieve that map from that workItemManager especially when the next node is a gateway

       

      2. When I use globals it is always stored as Object which is kinda unhandy

       

      ty in advance

        • 1. Re: passing data to nodes
          Demian Calcaprina Master

          You define process variables and then, in a task node, you receive parameters and put results. You map these parameters and results to process variables. So you share information between nodes with the process variables.

           

          In the work item handler, you retrieve the parameters from workItem.getParameters(), and you put the results in the way you mentioned (.completeWorkItem).

           

          If you are in a gateway, you can access directly to a process variable by its name. (you can use it in a constraint for example).

           

          Regards,

           

          Demian

          • 2. Re: passing data to nodes
            Darryl Youngblood Newbie

            I dont get it.

             

            When i start my process i can start it with some params stored in a map, like:

             

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

            boolean examOK = false;

            params.put("examOK", examOK);

             

            ksession.startProcess("com.sample.bpmn.hello", params);

             

            How can I access this map in a WorkItemHandler?

             

            When i try it like u told me:

             

            workItem.getParameter("examOK") or workItem.getParameters().get("examOK") i always get null

            • 3. Re: passing data to nodes
              Demian Calcaprina Master

              You start your process with this map.

               

              This will get keys from the map, and put them into the process variable you have defined.

               

              Then, in a task node, you have to map each process variable you will need to a node variable.

               

              Then, when you are in work item handler, you will get the parameters you have defined for this node, not all process variables.

               

              To make it more clear. If you are using Eclipse plugin,

              1) Define "examOK" variable in process. Click on process->Properties->Variables, and then add this variable

              2) Then, for example you have a custom node. Click on the node->Properties->Parameter Mapping, and then you put the name of the process variable, "examOK", and the name you will use it inside work item handler (it can be the same).

              3) Then, with workItem.getParameter("examOK") should work.

               

              Hope this helps,

               

              Demian

              1 of 1 people found this helpful
              • 4. Re: passing data to nodes
                Esteban Aliverti Master

                You are missing some steps in the middle

                 

                First of all, you need to declare each of the "variables" passed in startProcess() as process variables.

                Then you need to map the variables you want to use into your WorkItemHandler. In order to do this, you need to configure the input parameters of the Work Item Node. What you need to do is basically to map the process variable name with the work item variable name that you want to use.

                After you do this, you will be able to access the variable from within the Work Item Handler.

                 

                For further examples you can take a look at this set of examples: https://github.com/esteban-aliverti/JBPM-Samples

                1 of 1 people found this helpful
                • 5. Re: passing data to nodes
                  Ryan Peterson Newbie

                  I'm going through this myself, so far I've found:

                   

                  Put the variable into the map like you wrote:

                   

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

                  boolean examOK = false;

                  params.put("examOK", examOK);

                   

                  ksession.startProcess("com.sample.bpmn.hello", params);

                   

                   

                  Then in the bpmn definition, you need to have the process variables (if you want a global process variable I think?):

                  <itemDefinition id="_examOK" structureRef="java.lang.Boolean" />

                   

                  and within the process def itself (still in the .bpmn file):

                  <property id="examOK" itemSubjectRef="_examOK"/>

                   

                  You also need the dataInput mapped to your task (within your task, that lies inside the process):

                  <dataInput id="_999_examOK" name="examOK" />

                   

                  <inputSet>

                  <dataInputRefs>_999_examOK</dataInputRefs>

                  </inputSet>

                   

                  <dataInputAssociation>

                          <sourceRef>examOK</sourceRef>

                          <targetRef>_999_examOK</targetRef>

                  </dataInputAssociation>

                   

                   

                  That will map it into your workItemHandler, so you can obtain it via:

                  Boolean examOk = (Boolean) workItem.getParameter("examOK");

                   

                   

                  I'm not 100% sure if this is the "correct" way to implement this.  I'm unsure if this variable is global for all processes, for instance: what if the process is started multiple times for multiple users?  Does each process implementation get its own global examOk boolean using this method?

                  • 6. Re: passing data to nodes
                    Darryl Youngblood Newbie

                    Thank You all. It works now. :-)