Create and Resolve Incidents through Scripts(Javascript examples) (Internal API)

Code snippet if anyone wants to call this code in the future:

javascript:

function Incidents(){};
Incidents.prototype.createIncident = function(incidentType, incidentMessage) {

  var IncidentEntity  = Java.type('org.camunda.bpm.engine.impl.persistence.entity.IncidentEntity');
  var IncidentContext = Java.type('org.camunda.bpm.engine.impl.incident.IncidentContext');

  var context = new IncidentContext();
  context.setActivityId(execution.getCurrentActivityId());
  context.setExecutionId(execution.getProcessInstanceId());
  context.setProcessDefinitionId(execution.getProcessDefinitionId());

  var newIncident  = IncidentEntity.createAndInsertIncident(incidentType, context, incidentMessage);

  return newIncident;
};
 
Incidents.prototype.resolveIncident = function(incidentId){

    execution.getProcessEngineServices()
             .getRuntimeService()
             .createIncidentQuery()
             .incidentId(incidentId)
             .singleResult()
             .resolve();
};
1 Like