cancel
Showing results for 
Search instead for 
Did you mean: 

Add function to Nashorn Script API in Activiti

bhchemss
Star Contributor
Star Contributor

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 ?

Cheers

Chemss

1 ACCEPTED ANSWER

daisuke-yoshimo
Star Collaborator
Star Collaborator

I am sorry that I have not tried it.

Cannot you use load function?

(ex) load("http://example.com/script.js")

Nashorn and Shell Scripting 

View answer in original post

2 REPLIES 2

daisuke-yoshimo
Star Collaborator
Star Collaborator

I am sorry that I have not tried it.

Cannot you use load function?

(ex) load("http://example.com/script.js")

Nashorn and Shell Scripting 

That did the job ! and in an easy way , THANK YOU !