3 Replies Latest reply on Oct 28, 2012 10:40 PM by rickylkl

    Any help how to play with WorkItemHandler with parameter mapping ?

    rickylkl Newbie

      Halo all,

       

           Anyone can provide a sample that is work with parameter mapping on workitemhandler and it's success pass to next node to get back the parameter ?

           I was try many time but it show me:

           Could not find variable scope for variable test ...

       

           <dataOutputAssociation>

                <sourceRef>_32_subOutput</sourceRef>

                <targetRef>test</targetRef>

           </dataOutputAssociation>

       

           I really did try a lot of time, could anyone help !?

       

      Best Regards

        • 1. Re: Any help how to play with WorkItemHandler with parameter mapping ?
          rickylkl Newbie

          Dear,

           

          I try to update the src here.

           

          private void testDrlJbpm(Channel channel){

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

                              map.put("channel", channel);

                              map.put("x","hello world");

                              ksession.insert(channel);                                                  //          if there is a rule flow in workflow, need to insert obj to run rule

                              ksession.getWorkItemManager().registerWorkItemHandler("ShowRegPage", new RegistrationHandler());

                   ProcessInstance processInstance = (ProcessInstance) ksession.startProcess("testflow-web", map);          //          passing map inside the process, and use kcontext.getvariable() to get obj on if else case

                              System.out.println(processInstance.getEventTypes());

                              System.out.println(processInstance.getId());

                              System.out.println(processInstance.getProcessId());

                    ksession.fireAllRules();

                    }

           

           

          bpmn file:

            <itemDefinition id="_xItem" structureRef="String" />

            <itemDefinition id="_35-xItem" structureRef="String" />

            <itemDefinition id="_32-xItem" structureRef="String" />

            <itemDefinition id="_33-xItem" structureRef="String" />

            <process processType="Private" isExecutable="true" id="testflow-web" name="testflow-web" >

           

              <extensionElements>

               <tns:import name="org.drools.runtime.process.WorkflowProcessInstance" />

              </extensionElements>

              <!-- process variables -->

             <property id="x" itemSubjectRef="_xItem"/>

           

              <!-- nodes -->

              <task id="_35" name="ShowRegPage" tns:taskName="ShowRegPage" >

               <ioSpecification>

                  <dataInput id="_35_xInput" name="x" />

                  <inputSet>

                    <dataInputRefs>_35_xInput</dataInputRefs>

                  </inputSet>

                  <outputSet>

                  </outputSet>

                </ioSpecification>

                <dataInputAssociation>

                  <sourceRef>x</sourceRef>

                  <targetRef>_35_xInput</targetRef>

                </dataInputAssociation>

              </task>

           

           

          work item handler:

           

          @Override

                    public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {

            System.out.println("========= Executing registration =============" + workItem);

                    }

           

          result: workItem parameter cant not GET 'X' .... pls help

           

          Best Regards

          • 2. Re: Any help how to play with WorkItemHandler with parameter mapping ?
            Wooi Joe Chuah Newbie

            AFAIK, the map you inserted belongs to the ProcessInstance "testflow-web". Hence to get the data from the map, you have to obtain the ProcessInstance inside your work item handler then use the getVariable() method to obtain the parameter you passed in when you started the process.

             

            The parameter mapping used in the nodes in the diagram is for mapping variables which are present in the diagram itself (Open the bpmn diagram's properties and there is a row for variables where you can add/remove variables used in the Parameter Mapping