Once a user has claimed a task it stays with them until they complete it or, if enabled in your Self Service template, they "unclaim" it.
But what if a user claims a load of tasks then gets run over by a bus? Or what if the task is no longer relevant after a certain time? It's possible to programmatically unclaim tasks or even cancel them altogether.
Cancel with a Timer
This first example cancels a task with a timer. The timer starts counting down as soon as the execution arrives at the task, not when the task has been claimed (see below for an example of that).
A timer boundary event is attached to the user task. It has the "Cancel activity" property checked. When the timer expires/time is reached, the user task is cancelled and the execution continues along the path leading from the timer.
We don't advise looping back to the same task from a boundary event. If you do decide to, make sure the task has been cancelled before returning to it, otherwise duplicates will be created. You could continue the process on to another user task, perhaps assigned to an "escalation" user (this task could even use the same task form as the cancelled task).
Unclaim with a Script Task
Rather than cancelling a task you can use a script to remove the current user from it, allowing other eligible users to claim it.
The message flow from the user task is triggered when the task is claimed. This is possible because claiming a task sends a message to the process instance, in the format
For example, this user task has the ID "confirmtask":
The message event attached to it is listening for a message reference named
Note how the message event does not cancel the task - if it did the task would be cancelled as soon as it was claimed, making it impossible to complete.
The execution then arrives at a timer, which can be set to wait for however long you would like. Once the timer has expired the execution moves on to the script task.
The script task calls directly into the workflow engine. The call is only made if the task has not already completed, ie if the task has completed and set its
if (typeof _confirmtask_completed === "undefined") {
execution.getEngineServices().getTaskService().unclaim(_confirmtask_claimed.taskId);
}
Once the task has been unclaimed it can be picked up by any eligible candidate, including being reclaimed by the same user.