AnsweredAssumed Answered

Add function to Nashorn Script API in Activiti

Question asked by bhchemss on Sep 3, 2017
Latest reply on Sep 6, 2017 by bhchemss

Hi guys ,


I want to define a function that I can create from it an instance in every script task and use its methods,I dont want to define it in every script task (javascript format)

Example : 

function myFunction(a,b)={

return a+b;


Is it possible to add a class to Nashorn Script API of Activiti  to add this ?

I am by no mean a Java expert so please take me slowly

Something Like this :


import java.util.*;import javax.script.*;public class TestBindings {    public static void main(String args[]) throws Exception {        String script = "function myFunction(a,b) {return a+b;}";        ScriptEngine engine =  new ScriptEngineManager().getEngineByName("JavaScript");        CompiledScript cscript = compilingEngine.compile(script);        Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);               cscript.eval(bindings);         Invocable invocable = (Invocable) cscript.getEngine();        invocable.invokeFunction("myFunction");    }}

How to do this and where to place the class file and how to call the function inside the script task ?