New feature: JavaScript as process dialect

Since the 6.3.0.Final release is coming soon (we just pushed out second candidate release), there are quite a few exciting new features, and this blog will highlight one.
When defining your process logic, you can use scripts (small fragments of code) in various locations in the process definition.  You can use different languages (also called dialects) for this, and until now you had to choose between Java and MVEL as dialects (or if you’re an expert you could implement your own dialect) for action scripts and code constraints.
We have now also added support for JavaScript, which means you can write small fragments of JavaScript code as part of your process, both as action scripts (typically for manipulating variables) and constraints (in diverging gateways):
  • As action script:
    • Action script inside a Script Task
    • On-entry or on-exit actions scripts (in tasks supporting these, e.g. user tasks, call activity, rule tasks, etc.)
  • As constraint:
    • In diverging gateways (to decide which branch to take)

Inside these JavaScript fragments, you automatically have access to various properties (similar to how Java and MVEL actions scripts work):

  • Direct access to 
    • process variables
    • globals
  • A ‘kcontext‘ variable giving access to the ProcessContext (and through this you can get access to the active ProcessInstance, NodeInstance, KieSession, etc. and set variables)
To use the new dialect, simply select “JavaScript” as the script language (in one of the above describe situations), both in the web-based designer or the Eclipse Modeler.

For example, you could define an action script like:

kcontext.setVariable(‘surname’, “tester”);
var text = ‘Hello ‘;
print(text + kcontext.getVariable(‘name’) + ‘n’);
try {
    somethingInvalid;
} catch(err) {
    print(err + ‘n’);
}
// this is comment
print(person.name + ‘n’);

Or a constraint like:

person.name == ‘krisv’

Author

Comments are closed.