How to complete a UserTask via Java API?

We are using the camunda engine embedded within a Java application, and we use several of the BPMN features including UserTasks.

Our application takes full control of all tasks, so we do not assign them to any user in the BPMN itself. When we start a process containing such a UserTask, the task seems to be activated correctly (and the process is suspended, without any errors). But we are having trouble completing the waiting task from our application via the API.

We use the following strategy to interwork with Java: a listener attached at the entry point of every UserTask records its id (de.getActivityInstanceId), and then we execute taskService.complete(...), passing in the id captured at the entry-point, to enable process execution to continue.

But this strategy is not working for completing the UserTasks. The process engine complains that Cannot find task with id User-Activity:c5fc9d65-9bea-11e9-b89a-503eaa34ab97: task is null

What are we missing?

Thanks for any help with this.

Hi @sdg,

use the task.getId() ( instead of execution.getActivityInstanceId() (

Hope this helps, Ingo

1 Like

Hi Ingo,

Thanks for your thoughts.

I had tried a different approach in the mean time, and that also worked for me. Here are the details:

  1. My first step is unchanged: fetch and store (using Java code in a START listener) the activityInstanceId when the UserTask is entered.

  2. But in the second step (when the application needs to complete the suspended UserTask), I do not pass the previously stored activityInstanceId directly to TaskServiceā€™s complete() (as I was trying before). Instead, I use createTaskQuery() with activityInstanceIdIn() (passing the previously saved activityInstanceId) to list() the UserTask, and then pass the Id of that UserTask to TaskServiceā€™s complete().

But your suggested approach is much more compact, and I will give it a try later.