jBPM 6.2.0 Fetch Task ID in jBPM User Task Entry Script

1.1k views Asked by At

We need to update Task ID in jBPM User Task Entry Script into a process variable. Any idea how is it possible in jBPM 6.2.0

1

There are 1 answers

1
Ampie Barnard On BEST ANSWER

Unfortunately it won't be possible in the EntryScript, as the task would not have been created at that point, and hence the Task ID would not have been generated yet. However, depending on exactly why and where you would like to retrieve the task from, you could consider the following approach which does not require a process variable to store the task ID at all:

  1. You will find that the HumanTaskNodeInstance has a method getWorkItemId() which returns the Id of WorkItem used to create the Task with.
  2. You can retrieve a task by its WorkitemId in org.kie.api.task.TaskService.getTaskByWorkItemId().
  3. Hence if you know which HumanTaskNodeInstance was used to create the task, you can find the associated Task.

A second approach would be to register a TaskLifeCycleEventListener and override afterTaskAdded, but then you do not have easy access to the ProcessInstance we could pose a challenge.

A third approach would be to implement your own HumanTask WorkItemHandler, but that seems a bit hard handed for the requirement at hand.

Let me know if the first approach does not work and we can explore one of the other two approaches.