TaskListener.EVENTNAME_DELETE in combination with Transaction listener

Hi dear community,

I’m trying to implement a listener that would be fired after the delete event, so I could get the delete reason and other data that is recorded after the transaction is committed.

I’m using Camunda 7.13 CC, tomcat distribution.

When the transaction listener is fired I still can’t see the endTime and deleteReason, which I normally see if I call engine-rest/history/task on the deleted task.

@Service
public class CustomTaskListener implements TaskListener {
private final Logger LOGGER = Logger.getLogger(this.getClass().getName());
@Autowired
private HistoryService historyService;

@Override
public void notify(DelegateTask delegateTask) {

    TaskListenerOutput output = new TaskListenerOutput();
    output.setProcessInstanceId(delegateTask.getProcessInstanceId());
    output.setAssignee(delegateTask.getAssignee());
    output.setEventName(delegateTask.getEventName());
    output.setTaskName(delegateTask.getName());
    output.setTaskId(delegateTask.getId());

    HistoricTaskInstance taskInstance = historyService.createHistoricTaskInstanceQuery()
            .taskId(delegateTask.getId()).singleResult();
    if (taskInstance != null) {
        output.setSuperProcessInstanceId(taskInstance.getRootProcessInstanceId());
        output.setProcessDefinitionKey(taskInstance.getProcessDefinitionKey());
        output.setStartTime(taskInstance.getStartTime());

        if (delegateTask.getEventName().toLowerCase() == TaskListener.EVENTNAME_DELETE) {
            //transaction...
            TransactionContext transactionContext = Context.getCommandContext().getTransactionContext();
            transactionContext.addTransactionListener(TransactionState.COMMITTED, commandContext -> {

                HistoricTaskInstanceEntity taskEntity = commandContext.getHistoricTaskInstanceManager()
                        .findHistoricTaskInstanceById(delegateTask.getId());

                 //taskEntity.getDeleteReason() is null, as well as endTime and...
                LOGGER.info("FROM transaction... task delete reason: " + taskEntity.getDeleteReason());
            });              
        }
    }

    LOGGER.info(output.toString());
}

}

The User Task is set as Async Before.

Could you please advise on a correct way to get that data from a task listener?

Thanks in advance