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.
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.
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.
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.
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.
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?
I'm wondering if you got this solved, I'm having the same problem
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.