7 Replies Latest reply on Nov 13, 2013 5:13 AM by a_nat

    How to get the Task instance id ?

    a_nat Newbie

      Hi forum,


      I have a requirement to get the human task instance id from inside a process. Can you please suggest how to get it?


      On the onEntryActions of the human task, I have the following:




      But this doesn't give me the actual task instace id.




        • 1. How to get the Task instance id ?
          Kris Verlaenen Master



          You can cast kcontext.getNodeInstance() to WorkItemNodeInstance and use getWorkItemId() to get the id of the work item.

          You can then get the Task instance itself from the TaskServiceSession using getTaskByWorkItemId(..).


          Could you maybe share your use case why you need access to the task instance id?  Maybe there is another workaround as well.  It's for example easy to pass the task instance itself as a result parameter of the human task.



          • 2. How to get the Task instance id ?
            a_nat Newbie

            Hi Kris,


            Currently we are calling an external webservice on the On-entry actions of human task, so we would like to pass in the task instance id as the unique correlation id.


            Apart from the above, we would also like to inform the user of the task using an email service, so that he can look into the specific task instance.


            Kindy let me know, if you think of better options of doing the above.




            • 3. How to get the Task instance id ?
              a_nat Newbie

              Hi Kris,


              i'm not sure whether ((WorkItemNodeInstance)kcontext.getNodeInstance()).getWorkItemId() will return me a unique number every time for me to uniquely identify the tasks based on it.



              Im trying to complete the task using a java code (i.e., using org.jbpm.task.service.TaskClient), i only get void return from the method getTaskByWorkItemId(..).




              • 4. How to get the Task instance id ?
                Kris Verlaenen Master



                Yes, it will be unique for that session, or fully unique across sessions if you use persistence.


                The getTaskByWorkItemId() method uses asynchronous communication, so you need to provide a response handler that will be called asynch. and return the result.  Simply use the BlockingGetTaskResponseHandler if you want to get the result synchronously.



                • 5. Re: How to get the Task instance id ?
                  npereira Newbie

                  Hello Kris,


                  I have been experimenting on this but I haven't quite been successfull.

                  I attached some files with the BPMN and the java that I am using to debug the process.


                  The facth is that the Java code that is executed inside the bpmn, returns a WorkItem ID=2.


                                 System.out.println("Inside HT node 1");

                                  System.out.println("Process id is "+kcontext.getProcessInstance().getId());


                                  WorkItemNodeInstance wi = (WorkItemNodeInstance)kcontext.getNodeInstance();

                                  System.out.println("getWorkItemId is " + wi.getWorkItemId());

                                  System.out.println("WorkNodeID is " + wi.getId());


                                  System.out.println("WorkItem UniqueID is " + wi.getUniqueId());

                                  System.out.println("WorkItem ID " + wi.getId());


                                  String s2 = ""+kcontext.getNodeInstance().getId();

                                  System.out.println("Node Instance id is " +s2);


                  But once I get the Task, from de debug java class, the task WorkItem ID=1.


                               client.getTask(TID, responseHandler);

                              Task task = responseHandler.getTask();

                              TaskData td = task.getTaskData();

                              System.out.println("Task WorkItemID "+td.getWorkItemId());

                              BlockingTaskOperationResponseHandler eresponseHandler = new BlockingTaskOperationResponseHandler();

                              TaskOperationResponseHandler respHandler = null;

                              client.start(TID, "krisv", respHandler);

                              client.complete(TID, "krisv", null, eresponseHandler);


                  So there is no way to get a correlation between these two.

                  So how can I get this working?

                  • 6. Re: How to get the Task instance id ?
                    John Joel Boss Newbie

                    I'm wondering if you got this solved, I'm having the same problem

                    • 7. Re: How to get the Task instance id ?
                      a_nat Newbie


                      Currently No, we can't get it using kContext, which is a pain. Few other BPM engines support it and as far as I remeber jboss 3 supported it too.

                      Have created  [JBPM-4147] Able to use 'Task Variables' as expressions in Task properties - JBoss Issue Tracker