2 Replies Latest reply on Oct 30, 2013 10:53 AM by shumakriss

    Getting WorkItemId inside on entry action of a task node

    jjsaguit

      I am trying to get the work item Id of a work item by calling this code on the "on entry action" :

       

      long taskID=(java.lang.Long)(((org.jbpm.workflow.instance.node.WorkItemNodeInstance)kcontext.getNodeInstance()).getWorkItemId());
      int sessionID=(java.lang.Integer)((org.drools.runtime.StatefulKnowledgeSession)kcontext.getKnowledgeRuntime()).getId();
      System.out.println("task ID: "+taskID+"\n session ID: "+sessionID);
      

       

       

      This is for me to continue the work item later,

       

      I am getting the correct session ID, however the work item ID returns -1

       

      task ID: -1 (unexpected)

      session ID: 7368 (correct output)

       

       

      Can anyone help me? I have no idea what I'm doing wrong

       

      Jbpm version 5.4

        • 1. Re: Getting WorkItemId inside on entry action of a task node
          jjsaguit
          <bpmn2:task xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" id="_FC1D8CA3-EA31-49A6-947D-8B97638AB720" drools:selectable="true" xmlns:drools="http://www.jboss.org/drools" drools:taskName="HelloProcessExtension" name="HelloProcessExtension">
                <bpmn2:extensionElements>
                  <drools:onEntry-script scriptFormat="http://www.java.com/java">
                    <drools:script><![CDATA[System.out.println("task ID: "+((org.jbpm.workflow.instance.node.WorkItemNodeInstance)kcontext.getNodeInstance()).getWorkItemId()+"\n session ID: "+((org.drools.runtime.StatefulKnowledgeSession)kcontext.getKnowledgeRuntime()).getId());]]></drools:script>
                  </drools:onEntry-script>
                  <drools:onExit-script scriptFormat="http://www.java.com/java">
                    <drools:script><![CDATA[System.out.println("counter on exit "+counter);]]></drools:script>
                  </drools:onExit-script>
                </bpmn2:extensionElements>
                <bpmn2:incoming>_A05318B3-60F7-4A64-BBE7-669BC7689021</bpmn2:incoming>
                <bpmn2:outgoing>_0416D0D8-E02E-4E25-8E6E-C5B0E57C6D0F</bpmn2:outgoing>
                <bpmn2:ioSpecification id="_Rl0CHz-eEeOF0dk7aOoMYg">
                  <bpmn2:dataInput id="_FC1D8CA3-EA31-49A6-947D-8B97638AB720_TaskNameInput" name="TaskName"/>
                  <bpmn2:inputSet id="_Rl0CID-eEeOF0dk7aOoMYg"/>
                  <bpmn2:outputSet id="_Rl0CIT-eEeOF0dk7aOoMYg"/>
                </bpmn2:ioSpecification>
                <bpmn2:dataInputAssociation id="_Rl0CIj-eEeOF0dk7aOoMYg">
                  <bpmn2:targetRef>_FC1D8CA3-EA31-49A6-947D-8B97638AB720_TaskNameInput</bpmn2:targetRef>
                  <bpmn2:assignment id="_Rl0CIz-eEeOF0dk7aOoMYg">
                    <bpmn2:from xsi:type="bpmn2:tFormalExpression" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="_Rl0CJD-eEeOF0dk7aOoMYg">HelloProcessExtension</bpmn2:from>
                    <bpmn2:to xsi:type="bpmn2:tFormalExpression" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="_Rl0CJT-eEeOF0dk7aOoMYg">_FC1D8CA3-EA31-49A6-947D-8B97638AB720_TaskNameInput</bpmn2:to>
                  </bpmn2:assignment>
                </bpmn2:dataInputAssociation>
              </bpmn2:task>
          
          
          

           

          Here is the node source if it helps,

           

          Another test case, I managed to get the work item ID from the WorkItemHandler in my java code, however I want to get it in the "on entry action" inside guvnor

           

          *EDIT

           

          I am curious on what point does jbpm assign an "Id" to a work item.

          Here are my test results:

           

          • On node entry level:
            • 16:06:48,251 INFO  [stdout] (queue dispatcher thread) getWorkItemId is -1

           

          • Inside the work item handler:
            • 16:06:48,251 INFO  [stdout] (queue dispatcher thread) getWorkItemId is 8220

           

          • On node exit level:
            • 16:07:02,074 INFO  [stdout] (queue dispatcher thread) getWorkItemId is 8220

           

          It seems like the Id is assigned inside the handler, correct me if I'm wrong

           

          I'm looking for a way to get the Id before the handler is called or in the node entry level, Is there any way?

          • 2. Re: Getting WorkItemId inside on entry action of a task node
            shumakriss

            Hi John,

             

              It seems as though you are trying to access the workitemid from a node instance.  Check out the API:
            Knowledge API 5.2.0 API

             

            I believe what you want is to call getId from after calling getWorkItem as in Demian's example here:

            http://dcalca.wordpress.com/2011/09/03/on-enter-and-on-exit-node-actions-in-jbpm5/

             

            You may be interested to know this while examining the XML:
            JBPM5 Human Tasks, On-entry Actions

             

            I hope I am understanding your problem and this doesn't come much too late. Best of luck!