Can I replace FreeMarker texts in Inline-Javascript?

Hi,
I got a javascript typed input parameter which contains a FreeMarker-String.

Is it possible to process the FreeMarker-content inside the javascript? I found this old link, but it looks like thats this approach does not work for 7.10 anymore. ( I just get a TypeError: null has no such function “createBindings” error.

Best Regards

Alex

@Alex.Ph please share your javascript code you are using. Also what is your env? THis is the standard tomcat distro?

Hey, we are using camunda 7.10 with Wildfly 14.
I just create a new user task with an input parameter of type javascript with following test-code:

var ScriptEngine= new JavaImporter(javax.script);

with (ScriptEngine) {
var manager = new ScriptEngineManager();
var engine = manager.getEngineByName(“freemarker”);

var bindings = engine.createBindings();

“bla”;
};

Error: Unable to evaluate script:TypeError: null has no such function “createBindings” in

is freemarker installed as a dep?

https://docs.camunda.org/manual/7.10/user-guide/process-engine/templating/

Yes it is.
I can define a variable in user task A (test=ABC) and use it in task B ${test}. Or do these “magic” freemarker replacements have nothing to do with your provided link? :slight_smile:

Alex

your error seems to suggest that the var engine is returning null.

I would recommend you retry by using Groovy, and see if it returns a more robust error message.

Ok, I replaced the javascript code with groovy code:

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

manager = new ScriptEngineManager();
engine = manager.getEngineByName(“FreeMarker”);

println "engine: "+engine

The engine is null. I also tried “FreeMarker”. (“javascript” works btw).

I listed all available script engines. It looks like that I am not able to use freemarker at task execution time…:

2019-06-14 08:38:54,704 INFO [stdout] (default task-94) Oracle Nashorn
2019-06-14 08:38:54,706 INFO [stdout] (default task-94) 1.8.0_191
2019-06-14 08:38:54,707 INFO [stdout] (default task-94) ECMAScript
2019-06-14 08:38:54,708 INFO [stdout] (default task-94) ECMA - 262 Edition 5.1
2019-06-14 08:38:54,708 INFO [stdout] (default task-94) [js]
2019-06-14 08:38:54,709 INFO [stdout] (default task-94) [application/javascript, application/ecmascript, text/javascript, text/ecmascript]
2019-06-14 08:38:54,710 INFO [stdout] (default task-94) [nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript]

Run a script task with your script and see if works. Is it that you are running this as a inout mapping ?

I executed the script as script task and got the same results.
Before that I used an scrippted input parameter to execute the code.

Weird thing is, that I can use freeMarker scripts in user tasks, but the scriptEngine inside the script code does not find freemarker.

Do I have to enable “something” to be able to find freemarker in javascript or groovy scripts?

Can you download/pull the Camunda tomcat 7.10 docker image and test against that?

Mhh, Tomcat with camunda 7.10 knows freemarker … I have to check, how I can add freemarker to the scriptengine in wildfly

Groovy Scripting Engine
2.0
Groovy
2.4.13
[groovy]
[application/x-groovy]
[groovy, Groovy]
juel
1.0
JSP 2.1 EL
2.1
[juel]

[juel]
Oracle Nashorn
1.8.0_212
ECMAScript
ECMA - 262 Edition 5.1
[js]
[application/javascript, application/ecmascript, text/javascript, text/ecmascript]
[nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript]
freemarker
2.3.20
freemarker
2.3.20
[ftl]

[freemarker, Freemarker, FreeMarker]

So you have followed these instructions ? https://docs.camunda.org/manual/7.10/user-guide/process-engine/templating/

No I didnt, because we are using the prepacked docker distribution.
But I checked the instruction and had a look into the folder and modules. Everything seems setup correctly out of the box, but the script doesnt list the freemarker engine.

I think will create a new thread in the process-engine forum, cause this issue has nothing to do with the modeler anymore.

Thnx for the help so far :slight_smile: