3 Replies Latest reply on Jun 14, 2016 9:38 PM by imphilippesimo

    How can i get the human task id defined in bpmn files?

    jay zhang Newbie

      List<TaskSummary> tasklst = client.getTasksByStatusByProcessId(processInstanceId, parmlst, "en-UK");

      long taskid = tasklst.get(0).getId();

       

      this taskid is not the the human task id defined in bpmn files,but how can i get the  the human task id defined in bpmn files here.

        • 1. Re: How can i get the human task id defined in bpmn files?
          Shobhit Tyagi Master

          I believe you have the process instance ID. So you can find the process definition id using the instance id first.

          Using the process def id, you will need to find the Process object to get the node related information.

          Here is what you can do,

           

          String strProcessDefId = JPAProcessInstanceDbLog.findProcessInstance(intProcessInstId).getProcessId(); // Get process def id.
             
          readKnowledgeBase(); // Get the knowledge base by feeding it the process name.
           Process objProcess = objKBase.getProcess(strProcessDefId); // Process object.
             for (Node objNode : ((WorkflowProcessImpl) objProcess).getNodes())
             {
               Map<String, Object> hshMetaData = objNode.getMetaData();
               System.out.println(hshMetaData.get("UniqueId"));
              }
          

           

          Regards.

          1 of 1 people found this helpful
          • 2. Re: How can i get the human task id defined in bpmn files?
            jay zhang Newbie

            Thank you!

            I solve the problem in this way:

            //get session

                                          StatefulKnowledgeSession sess = this.jbpm5helper.buildJbpmSession(0);

                                          //get processInstance by processInstanceId

                                          RuleFlowProcessInstance processInstance=(RuleFlowProcessInstance)sess.getProcessInstance(processInstanceId);

                                          //get the id of node To be executed

                                          List<NodeInstance> nodeList=(List<NodeInstance>)processInstance.getNodeInstances();

                                          int currentNodeId=(int)nodeList.get(0).getNodeId();

            • 3. Re: How can i get the human task id defined in bpmn files?
              imphilippesimo Newbie

              hi, may be its too late but i hope this could be helpful for someone else

               

              try this method

               

               

              List<Long> getHumanTaskNodes(String processIdAsString, RuntimeEnvironment environment) {

                  List<Long> nodeIds = new ArrayList<Long>();

                  WorkflowProcess workflowProcess = (WorkflowProcess) environment

                      .getKieBase().getProcess(processIdAsString);

                  for (Node node : workflowProcess.getNodes()) {

                      if (node instanceof CompositeContextNode) {

                      for (Node inNode : ((CompositeContextNode) node).getNodes())

                          if (inNode instanceof HumanTaskNode)

                          nodeIds.add(inNode.getId());

               

                      } else if (node instanceof HumanTaskNode)

                      nodeIds.add(node.getId());

               

                  }

               

                  return nodeIds;

                  }

               

              Here you have all your humanTasks ids