Get list of all instance incidents (FailedJobs) on JavaScript

Hello, can you help me get list of all instance incidents of FailedJobs type?
I want to put this script into task field in Modeler. I tried execution.getIncidents(), and it could return my custom created incidents, but I am not able to get FailedJob.

Hi @Mikhail.Savelov,

If the purpose is to query incidents periodically then
I prefer to have a separate process to query incidents.

Below test queries contain examples for
queryByIncidentType
queryByProcessDefinitionKeys
queryByProcessDefinitionId

Thank you, but I don’t want to use Java and implement complicated logic here. All I want is to verify: is there any incidents in current instance, by using JavaScript in inline script. Like I said, execution.getIncidents() is working, but not for FailingJobs. I want something very simple like that

@Mikhail.Savelov you can try like below in script/service tasks:

// Only select jobs that failed due to an exception at an activity
// with the given id.
var jobCount = execution.getProcessEngineServices().getManagementService()
       .createJobQuery().failedActivityId("failedActivityId").count();
        
// Only select incidents which were created due to a failure at an activity
// with the given id.
var incidentCount = execution.getProcessEngineServices().getRuntimeService()
       .createIncidentQuery().failedActivityId("failedActivityId").count();