09-03-2017 09:14 AM
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
09-05-2017 10:22 AM
I am sorry that I have not tried it.
Cannot you use load function?
(ex) load("http://example.com/script.js")
09-05-2017 10:22 AM
I am sorry that I have not tried it.
Cannot you use load function?
(ex) load("http://example.com/script.js")
09-06-2017 07:13 AM
That did the job ! and in an easy way , THANK YOU !
Explore our Alfresco products with the links below. Use labels to filter content by product module.