Based on the conversations in: Getting Stack Trace in Boundary Error Event - #12 by StephenOTT
Wanted to move it into its own thread for better discoverability:
Came up with the following:
Where Generate Incident is:
(Javascript)
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("myCustomIncidentType", context, "A custom incident message.");
newIncident.id
I store the newIncident.id
as a process variable (result variable in the script task) so in the next task i can search for it and resolve it.
The Resolve Incident task has a Execution Listener
with a End
type:
(Javascript)
execution.getProcessEngineServices().getRuntimeService().createIncidentQuery().incidentId(execution.getVariable('IncidentId')).singleResult().resolve();
This finds the Incident with the IndicidentId process variable as the filter and resolves it. I had to do this, because as far as i can tell there is no Web API to resolve incidents? Incident | docs.camunda.org But maybe i am missing something?
Update: found the following that shows it has been a feature request for a while: https://app.camunda.com/jira/browse/CAM-1689 (“I can create / resolve an incident through public API”)
Where .createIncidentQuery()
returns a instance of IncidentEntity, and .resolve()
is (IncidentEntity (camunda BPM Javadocs 7.6.13-ee))
In Cockpit there is not ability to “resolve” the incidents as a action. Would be nice to have a “generic” resolve function in Cockpit, so you can generate a Incident and resolve it without having to write and deploy custom Java.
Some screenshots of what it looks like in Cockpit:
With Two process instances (1 with a incident, and the other had its incident resolved)
Instance with the Incident:
Instance with the Incident, in the Incidents Tab:
Instance with its Incident Resolved:
References:
- General Info: Incidents | docs.camunda.org
- Example I based my search on: https://github.com/camunda/camunda-consulting/blob/master/snippets/custom-incident/src/main/java/com/camunda/bpm/demo/custom_incident/CreateCustomIncidentTaskListener.java
- Important!: The Incident Entity: IncidentEntity (camunda BPM Javadocs 7.6.13-ee)
- How i find the Entity to resolve it in another task: IncidentQuery (camunda BPM Javadocs 7.6.13-ee)
- Important!: How to create the Context object which is used by the IncidentEntity in #3 above: IncidentContext (camunda BPM Javadocs 7.6.13-ee)