I am deleting a process instance by using java api
deleteProcessInstance( “comments”);
I wanted to have a call back when the process instance is deleted. How shall i achieve this use case
@kv8288 You need to add Execution listener with event type as “End” at the process level.
<bpmn:process id="DeleteInstanceExecutionListener" name="DeleteInstanceExecutionListener Test" isExecutable="true" camunda:historyTimeToLive="P1D">
<bpmn:extensionElements>
<camunda:executionListener delegateExpression="${deleteInstanceExecutionListener}" event="end" />
</bpmn:extensionElements>
...
...
...
Delete process instance code:
runtimeService.deleteProcessInstance(processInstanceId, deleteReason, false);
Execution Listener code:
@Slf4j
@Component(value = "deleteInstanceExecutionListener")
public class DeleteInstanceExecutionListener implements ExecutionListener {
@Override
public void notify(DelegateExecution execution) throws Exception {
log.info("Executing {} for event type {}", this.getClass().getName(), execution.getEventName());
}
}
BPMN File
<?xml version="1.0" encoding="UTF-8"?><bpmn:definitions xmlns:bpmn=“http://www.omg.org/spec/BPMN/20100524/MODEL” xmlns:bpmndi=“http://www.omg.org/spec/BPMN/20100524/DI” xmlns:dc=“http://www.omg.org/spec/DD/20100524/DC” xmlns:camunda=“http://camunda.org/schema/1.0/bpmn” xmlns:di=“http://www.omg.org/spec/DD/20100524/DI” xmlns:modeler=“http://camunda.org/schema/modeler/1.0” id=“Definitions_1uu5bmo” targetNamespace=“http://bpmn.io/schema/bpmn” exporter=“Camunda Modeler” exporterVersion=“4.12.0” modeler:executionPlatform=“Camunda Platform” modeler:executionPlatformVersion=“7.15.0”>
<bpmn:process id=“DeleteInstanceExecutionListener” name=“DeleteInstanceExecutionListener Test” isExecutable=“true” camunda:historyTimeToLive=“P1D”>
bpmn:extensionElements
<camunda:executionListener delegateExpression="${deleteInstanceExecutionListener}" event=“end” />
</bpmn:extensionElements>
<bpmn:startEvent id=“StartEvent_1”>
bpmn:outgoingFlow_1srbck7</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id=“Flow_1srbck7” sourceRef=“StartEvent_1” targetRef=“Activity_19eytbm” />
<bpmn:userTask id=“Activity_19eytbm” name=“Check Reports” camunda:assignee=“demo”>
bpmn:incomingFlow_1srbck7</bpmn:incoming>
bpmn:outgoingFlow_1uk1rsu</bpmn:outgoing>
</bpmn:userTask>
<bpmn:endEvent id=“Event_03p758a”>
bpmn:incomingFlow_1uk1rsu</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id=“Flow_1uk1rsu” sourceRef=“Activity_19eytbm” targetRef=“Event_03p758a” />
</bpmn:process>
<bpmndi:BPMNDiagram id=“BPMNDiagram_1”>
<bpmndi:BPMNPlane id=“BPMNPlane_1” bpmnElement=“DeleteInstanceExecutionListener”>
<bpmndi:BPMNEdge id=“Flow_1srbck7_di” bpmnElement=“Flow_1srbck7”>
<di:waypoint x=“215” y=“117” />
<di:waypoint x=“270” y=“117” />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id=“Flow_1uk1rsu_di” bpmnElement=“Flow_1uk1rsu”>
<di:waypoint x=“370” y=“117” />
<di:waypoint x=“432” y=“117” />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement=“StartEvent_1”>
<dc:Bounds x=“179” y=“99” width=“36” height=“36” />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id=“Activity_1f60c2x_di” bpmnElement=“Activity_19eytbm”>
<dc:Bounds x=“270” y=“77” width=“100” height=“80” />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id=“Event_03p758a_di” bpmnElement=“Event_03p758a”>
<dc:Bounds x=“432” y=“99” width=“36” height=“36” />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
Logs:
INFO[0;39m e[35mc.b.c.s.i.ProcessInstanceServiceImple[0;39m - Initiating process DeleteInstanceExecutionListener for businessKey 100001
INFO[0;39m e[35mc.b.c.s.i.ProcessInstanceServiceImple[0;39m - Process initiated with id: 8de5042b-ba7c-11ec-af39-72ecf1bfe48c
INFO[0;39m e[35mc.b.c.e.DeleteInstanceExecutionListenere[0;39m - Executing com.bpm.camunda.executionlisteners.DeleteInstanceExecutionListener for event type end