Add function to Nashorn Script API in Activiti

cancel
Showing results for 
Search instead for 
Did you mean: 
bhchemss
Established Member

Add function to Nashorn Script API in Activiti

Jump to solution

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 Solution

Accepted Solutions
daisuke-yoshimo
Senior Member

Re: Add function to Nashorn Script API in Activiti

Jump to solution

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 solution in original post

2 Replies
daisuke-yoshimo
Senior Member

Re: Add function to Nashorn Script API in Activiti

Jump to solution

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 

bhchemss
Established Member

Re: Add function to Nashorn Script API in Activiti

Jump to solution

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