The Java class implementing a Status Transition Rule Script is de.ecm4u.sbcs.sm.core.rule.NashornRule.
Status Transition Rule Scripts are implements in JavaScript using the Nashorn engine. A script must provie a single function called run that returns a result object. Thos object has two array members, add and remove, that contain the names of the status values to add and remove from the list of reachable status values read from the status_transition table.
The basic structure of a script looks like this.
function run() {
var toAdd = [];
var toRemove = [];
// Add status values to add and remove and push them onto toAdd and toRemove.
return {
add: toAdd,
remove: toRemove
}
}
The script has access to various context objects that contain information about the current state from which transitions are calculated.
flow: A string containing the name of the flow.status: A string containing the name of the status.statusValue: A string containing the name of the current status value.roles: An array of strings containing the roles the executing user has.context: An object with string values set by the REST client requesting the evaluation.logger: An org.slf4j.Logger instance.The body of the run function can use these context objects to calculate which status values are to be pushed onto toAdd and toRemove.
Scripts can be located anywhere in the filesystem the SBCS Status Machine Service can read from. It is recommended to put them into /etc/ecm4u/sbcs-sm/scripts/.