Retain history for terminated process instance

We need to terminate some of the running process instances, however, we need to retain the history.

runtimeService.deleteProcessInstance terminates the process instance and history.

Is there a option to retain the history for the terminated process instance?

Hi,

runtimeService.deleteProcessInstance deletes process instance, but its history is kept.

@Test
@Deployment(resources = { "org/flowable/engine/test/history/oneTaskProcess.bpmn20.xml" })
public void testDeleteProcessInstanceHistoryCreated() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    assertNotNull(processInstance);

    // delete process instance should not delete the history
    runtimeService.deleteProcessInstance(processInstance.getId(), "cancel");
    
    waitForHistoryJobExecutorToProcessAllJobs(7000, 100);
    
    HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(historicProcessInstance.getEndTime());
}

Regards
Martin

1 Like

Thanks martin you are right.
I am looking at different place.