Resolving incidents after execution

As long as the process has incidents (and is still running), it is no Historic Instance.
For retrieving Historic Incidents you need the HistoryService, runtimeService always just returns stuff for running processes.

But as far as I know it’s not possible that a process has more than one Incident. (@Askar ?)

To execute your Code in command context you have to retrieve the Command Executer, e.g. like this:

CommandExecutor executor = Context.getProcessEngineConfiguration().getCommandExecutorTxRequired()

Then you have to wrap your code in a command, and execute this command with the executer. E.g.:

executor.execute((commandContext) -> {
  List<Incident> incidentList = runtimeService.createIncidentQuery().processInstanceId(processInstanceId).list();
  for (Incident inc : incidentList) {
    IncidentEntity entity = (IncidentEntity) inc;
    entity.resolve();
  }
}

Hope that helps!

Best regards,
Patrick

1 Like