Cancel a UserTask

Assuming the following use case: A user can cancel a User Task and based on that the flow of the process should change. Example: Normal flow is A -> B -> C -> end, Task B canceled flow: A-> D -> end.

Proposed solution: Creating a subprocess for every task that can be cancelled. The user cancels the task by calling the complete endpoint with a cancel_variable=True. A gateway check if the tasks was cancelled and if it was it will throw a boundary event (Escalation Event). Using the boundary event the flow of the process would change.

But I’m not sure that this would be the best practice approach of the problem, what do you think about this solution? Do you have a better approach to this use case?

Thank you,
Razvan Todea.

Can you upload a model, it would help understanding your proposed solution.

If Task B get’s cancelled I don’t want Task C to be executed.
My concern is that I’m setting the cancel_task variable on the complete endpoint. I feel like this is a hacky solution and I’m not using the Camunda API to it’s maximum. Maybe this could be implemented different by removing the gateway and using a Transaction with an Cancel Event instead or something like that.

cancel-task.bpmn (9.9 KB)

Under what circumstances do you expect to run task D?

Only if Task B gets cancelled somehow.

And in both cases weather B is Cancelled or not, you’d still like to run the Service Task?

Yes, for this use case.

OK, well then this might work slighted better than your solution (although i’m sorry to say it doesn’t need to use anything particularly advanced :slight_smile: )

You suggest to still set the cancel_task variable on the complete endpoint of the task, but replace the gateway with a Boundary Event, right?

Thank you for the solution.

Exactly! the boundary event would be implemented like this:

And the variable would be passed to the instance on the complete call

That’s great!

One more think though, lets say that I don’t want to set the cancel_task variable in the complete endpoint.
Instead I to call the process-instance/{instance_id}/modification endpoint with this payload: { "skipCustomListeners": true, "skipIoMappings": true, "instructions": [ { "type": "cancel", "activityInstanceId": "taskBInstanceId" } ] }, is there a way to know that Task B was cancelled and switch the flow to Task D?

So you’d like to see that task B has been cancelled in camunda?
In that case i would change the model slightly to actually interrupt the task and thus show that it has been cancelled if the complete call is done with the cancel task variable set

Actually I was suggesting to not use the complete endpoint for cancelling, instead use process-instance/{instance_id}/modification endpoint to cancel the task and instead of the Conditional Event to use a Cancel Boundary Event on TaskB. Is this solution possible?

If the solution from above is not possible I will stick with the complete solution that you’ve confirm.

Thank you for the support,
Razvan Todea.