Unable to suspend the process in incident handler

Hi following my code,

public class FailedJobIncidentHandler extends DefaultIncidentHandler {
public static final Logger LOG = LoggerFactory.getLogger(FailedJobIncidentHandler.class);

public FailedJobIncidentHandler(String type) {
    super(type);
    LOG.info("IncidentHandler created for type '{}'", type);
}

@Override
public String getIncidentHandlerType() {
    return Incident.FAILED_JOB_HANDLER_TYPE;
}

@Override
public Incident handleIncident(IncidentContext context, String message) {
    IncidentEntity incidentEntity = (IncidentEntity) super.handleIncident(context, message);
    LOG.info("incident {} created for execution {}", incidentEntity.getId(), context.getExecutionId());
    ExecutionEntity execution = Context.getCommandContext().getExecutionManager()
            .findExecutionById(context.getExecutionId());

    if (execution == null) {
        LOG.warn("");
    } else if (execution.getProcessInstanceId() != null) {
        LOG.info("Hello");
        execution.getProcessEngineServices().getRuntimeService().updateProcessInstanceSuspensionState()
                .byProcessInstanceId(execution.getProcessInstanceId()).suspend();
    }
    return incidentEntity;
}

}

I would like to stop my process instance in this handler. Could someone help me with this? GET_interfaces.bpmn (2.5 KB)

Hi @Sowmiya, you can try like below,

Context.getCommandContext().getTransactionContext().addTransactionListener(TransactionState.COMMITTED, commandContext -> { runtimeService.suspendProcessInstanceById(execution.getProcessInstanceId())});
1 Like