*Camunda Platform 8, our cloud-native solution for process orchestration, launched in April 2022. Images and supporting documentation in this post may reflect an earlier version of our cloud and software solutions.
How can I delete an open human task and running process instances?
We’ve already covered how to delete an entire process instance, so let’s dive into how to delete a human (or other) task associated with a running process.
Canceling a specific task, or even an open human task, is very similar. However, let’s go through it step-by-step, just to be clear.
Again, the screenshots are all from Camunda Platform 7 Enterprise Edition. Camunda Platform 7 Community Edition doesn’t have these handy buttons in the web application, but you can accomplish the same things via the REST API. I strongly suggest enabling the Swagger UI in your Camunda Platform 7 Community Edition so that you can go to http://localhost:8080/swaggerui and run these REST calls from there, but I’ll also include the curl commands here.
4 steps to delete an open human task
1. First, we need to go to Camunda Cockpit and look for the human task we want to delete.
2. Once we’ve identified the human task we want to delete, click on that task.
Now we can see the Task ID, Instance ID, and Definition Key associated with that human task. Clicking on the Task ID will open up the process model, showing where the specific task is in the process.
Hovering our mouse over that instance will show us a bit more information about the task we’re viewing.
3. Once we are sure we have the right process task instance, we can go up to the far right corner and click Cancel to delete it. It’s important to keep in mind that if this is the only task for the process, deleting it will delete the entire process, so be careful with this one.
4. We will, of course, want to confirm that this is indeed what we want to do. Click Cancel Process Instance to confirm.
Here we get confirmation that the process instance has been canceled.
We can then see visual confirmation in the process model that the process and the associated incident were indeed canceled.
And there you have it, your open human (user) task is canceled!
To do this via the REST API, you have to get a list of the tasks first:
curl -X GET "http://localhost:8080/engine-rest/process-instance"
Which will return a JSON object with all the current tasks in it:
[
{
"links": [],
"id": "00dd212e-8537-11ec-a27e-0242661ea8d3",
"definitionId": "Process_16ydxvz:1:d966207d-7258-11ec-91a0-0242661ea8d3",
"businessKey": null,
"caseInstanceId": null,
"ended": false,
"suspended": false,
"tenantId": null
},
{
"links": [],
"id": "0893aa99-6363-11ec-952c-0242661ea8d3",
"definitionId": "Greenhouse:1:bc8f858f-6362-11ec-952c-0242661ea8d3",
"businessKey": null,
"caseInstanceId": null,
"ended": false,
"suspended": true,
"tenantId": null
},
This will give you a list of process instances, so you can then choose the process instance you are interested and make another REST call using the appropriate process instance ID.
curl -X GET “http://localhost:8080/engine-rest/process-instance/00dd212e-8537-11ec-a27e-0242661ea8d3/activity-instances
This will return a complete list of any activity instances that the process instance owns.
{
"id": "00dd212e-8537-11ec-a27e-0242661ea8d3",
"parentActivityInstanceId": null,
"activityId": "Process_16ydxvz:1:d966207d-7258-11ec-91a0-0242661ea8d3",
"activityType": "processDefinition",
"processInstanceId": "00dd212e-8537-11ec-a27e-0242661ea8d3",
"processDefinitionId": "Process_16ydxvz:1:d966207d-7258-11ec-91a0-0242661ea8d3",
"childActivityInstances": [
{
"id": "Activity_18sf37u:00dd4840-8537-11ec-a27e-0242661ea8d3",
"parentActivityInstanceId": "00dd212e-8537-11ec-a27e-0242661ea8d3",
"activityId": "Activity_18sf37u",
"activityType": "userTask",
"processInstanceId": "00dd212e-8537-11ec-a27e-0242661ea8d3",
"processDefinitionId": "Process_16ydxvz:1:d966207d-7258-11ec-91a0-0242661ea8d3",
"childActivityInstances": [],
"childTransitionInstances": [],
"executionIds": [
"00dd212e-8537-11ec-a27e-0242661ea8d3"
],
"activityName": "What to eat",
"incidentIds": [],
"incidents": [],
"name": "What to eat"
}
],
"childTransitionInstances": [],
"executionIds": [
"00dd212e-8537-11ec-a27e-0242661ea8d3"
],
"activityName": null,
"incidentIds": [],
"incidents": [],
"name": null
}
Now that we have the child activity information, we can cancel it. But we won’t be using a ‘delete’ REST call. What we’ll actually do is modify the activity instance via a call to the /process-instance{id}/modify endpoint. In the above example, that would mean calling:
curl -X POST
“http://localhost:8080/process-instance/00dd212e-8537-11ec-a27e-0242661ea8d3/modify
with the following JSON payload:
{
"id": "00dd212e-8537-11ec-a27e-0242661ea8d3",
"skipCustomListeners": true,
"skipIoMappings": true,
"instructions": [
{
"type": "cancel",
"activityInstanceId": "Activity_18sf37u:00dd4840-8537-11ec-a27e-0242661ea8d3"
}
]
}
This will return an empty `204` message indicating that the call succeeded, and the activity instance (in this case a human task) will be canceled.
Cancellation Complete
Now you know how to cancel a task in both Camunda Platform 7 Enterprise Edition and Camunda Platform 7 Community Edition.