Scripting Incident Handlers: Use Nashorn/javascript to execute Incident Handlers (Process Engine Plugin)

Little plugin to help anyone with more dynamic incident handler activity:

This plugin lets you write javascript that will execute for the handleIncident, resolveIncident, and deleteIncident methods.

You can deploy your javascript as part of your process deployment, and in your BPMN use the Camunda Extension Properties on the BPMN/BPMN Pool(s) to tell the plugin what to do.

Configuring the Plugin

...

<plugin>
    <class>io.digitalstate.camunda.NashornIncidentHandlerProcessEnginePlugin</class>
    <properties>
        <property name="incidentTypes">failedJob,failedExternalTask,incidentType2,incidentType3</property>
    </properties>
</plugin>

...

Notice that you can apply the plugin to multiple incidentTypes.

Then setup your BPMN to have the extension properties as in the images above.

example script

incident.js

var system = java.lang.System

function handleIncident(){
  system.out.println("This is a handleIncident Function Message: ");
  system.out.println(incidentContext.getProcessDefinitionId())
  system.out.println(incidentMessage)
}

function resolveIncident(){
  system.out.println("This is executed when the incident was resolved");
}

function deleteIncident(){
  system.out.println("This is executed when the incident was deleted");
}

Then upload your BPMN as a process deployment, and the rest is taken care for you.

Further docs are in the readme.

See the docker folder for a working example.

2 Likes