Cancellations
Unfortunately, it happens that the contract for the new developer gets cancelled when the onboarding is ongoing. Sometimes it’s Trainink who cancels, other times it’s the hired developer. In both cases, the onboarding needs to be aborted.
A BPMN Event subprocess is very suitable to handle this situation.
Add a new Expanded Sub process to the model from the palette in an empty area. It can be free-floating from the rest of the process elements, because an Event subprocess is triggered by an event, not by control flow from the rest of the model. Use the wrench icon in the pop over menu to change its type to Event Sub Process. The border is drawn as a dotted line.
There will be a start event in the new sub process.
Select it and change its type to Message Start Event.
Give it the name Contract cancelled.
In the same way as you did before, use the start event’s properties to configure the name of the message it will be triggered by.
Use the message name cancel-contract.
Add a new user task Clean up to the model by connecting it to the Contract cancelled start event inside the event sub process. Make the sub process larger if you need some more space. Connect the user task to an end event inside the sub process and name the end event Onboarding aborted.
An event sub process is triggered by the event of its start event, at any time during the process scope it is part of.
In this case, the sub process is part of the "root" process to onboard a developer and that means that sending a message cancel-contract at any time will trigger the sub process.
Testing Cancellations
Save and deploy the updated process model.
Start a new process instance.
Go into Cockpit to see that it’s running.
Send the cancel-contract message in the same way you did for the receive task.
curl --header "Content-Type: application/json" \
--request POST \
--data '{"messageName" : "cancel-contract", "resultEnabled": true}' \
http://localhost:8080/engine-rest/message
Check in Cockpit that the same process instance is now waiting in the Clean up user task. When you complete that task (via Tasklist or using the API as you did before), the process instance will have completed.
Test the behaviour also works when the process is further along by completing some steps and then sending the message for the cancellation. You’ve successfully added cancellation at any point to the process model, well done!