incidentQuery with filter by DefinitionKey

Hallo,

Is there an easy way to query all incidents (eg. failedExternalTasks) for a given processDefinitionKey?

I want to get all incidents for all existing process versions.

My solution so far:

  • Get all incidents by type (failedExternalTasks)
  • Iterate all incidents, get the process instance associated with the incident
  • and filter by the processkey.

I am using the JavaAPI with Camunda Version 7.14.

kind regards,
Heiko

1 Like

Hi @HeikoSpindler,

you can access all incidents with this REST api: Get Incidents | docs.camunda.org

In Java you have to write runtimeService.createIncidentQuery().list().

You can add several query parameters to filter certain incidents.

Hope this helps, Ingo

Hi Ingo,
that is the question:
Is there an easy way (a query parameter) to query all incidents for a given processKey?
For now I find options for processId, incidentType, only.

I want a more handsome solution for this helper method:

public static List<Incident> getIncidentsForProcessKey( DelegateExecution delegateExecution, String workflowName) {
    List<Incident> resultList = new ArrayList<>();
    List<Incident> incidentList = delegateExecution
            .getProcessEngineServices()
            .getRuntimeService()
            .createIncidentQuery()
            .incidentType("failedExternalTask")
            .list();

    for ( Incident incident : incidentList ) {

        ProcessInstance processInstance = delegateExecution
                .getProcessEngineServices()
                .getRuntimeService()
                .createProcessInstanceQuery()
                .processInstanceId(incident.getProcessInstanceId())
                .singleResult();

        if ( processInstance.getProcessDefinitionId().startsWith(workflowName)) {
            resultList.add(incident);
        }
    }
    return resultList;
}

kind regard,
Heiko

Hi @HeikoSpindler,

what is the content of workflowName? If it contains the Process ID from the Modeler, you can use this:

runtimeService.createIncidentQuery().processDefinitionKeyIn(workflowName).list(); 

Hope this helps, Ingo

2 Likes

Hi Ingo,

Oh, yes. “processDefinitionKeyIn(workflowName)” works for me.
Thanks, for your help,
kind regards,
Heiko