3 Replies Latest reply on Jan 8, 2014 4:07 AM by swiderski.maciej

    How to get BPMN node id using API?

    ghollins

      Hi,

       

         In a WorkItemHandler, I need to get the a node's ID.  For example in the following example I would want to get "_86409638-AE00-4A3C-BE97-32E1E8108BF4"

       

       

      <bpmn2:serviceTask id="_86409638-AE00-4A3C-BE97-32E1E8108BF4" name="foo" ...

      ...

      </bpmn2:serviceTask>

       

      I have access to WorkItem and WorkItemManager:

       

      public void executeWorkItem(WorkItem workItem, WorkItemManager manager)


      However, workItem, only has access to an "id" that is a long value.. 

      I even tried getting access via the NodeInstance, but I don't see any methods that help me.  For example:

       

      org.kie.api.runtime.process.NodeInstance ni = processInstance.getNodeInstance(workItem.getId());


      Any ideas?


      Thanks,

      Galen

        • 1. Re: How to get BPMN node id using API?
          swiderski.maciej

          from NodeInstance you can get access to Node which then has map of metadata and one of the metadata is the id of the node, it is stored under UniqueId key in the meta data map.

           

          HTH

          • 2. Re: Re: How to get BPMN node id using API?
            ghollins

            Hi Maciej,

             

              Thanks for the pointer.  However, I'm unable to get a NodeInstance.  Perhaps I'm using the wrong ID?  Here is code I have tried:

             

              org.kie.api.runtime.process.NodeInstance ni = processInstance.getNodeInstance(workItem.getProcessInstanceId());

              org.kie.api.runtime.process.NodeInstance ni2 = processInstance.getNodeInstance(workItem.getId());

              log.info("NODE INSTANCE: "+ni+" (for workItem.getProcessInstanceId() = "+workItem.getProcessInstanceId()+")");

              log.info("NODE INSTANCE: "+ni2+" (for workItem.getId() = "+workItem.getId()+")");

             

            And this is the output:

             

            NODE INSTANCE: null (for workItem.getProcessInstanceId() = 196)

            NODE INSTANCE: null (for workItem.getId() = 1019)

             

            As you can see, I'm getting null for the NodeInstance variables.  How do I get the nodeInstanceId from the workItem?

             

            Thanks,

            Galen

            • 3. Re: How to get BPMN node id using API?
              swiderski.maciej

              take a look here for details on how to find node instance for work item.

               

              HTH