Can I evaluate JUEL string inside a Javascript task?

I realize I may be stretching what Camunda was intended for … however …

Inside a Script task I want to read a txt file into a string (I can do this). This txt file may contain JUEL expressions, so I want the script to call something to process the expressions and return a ‘clean’ string.

I have tried and succeeded having the txt file Javascript compatible and doing an eval on it, but I really don’t want to go that way.

Does anyone have any suggestions?

You can access freemarker engine or the expression engine and parse your text with it

Take a look at Freemarker Script: Greater than 4000 char, exceeding historic variable instance DB insert on how to use another engine within the Js engine.

Will freemarker have access to all of the Camunda variables? Essentially, I am reading in a payload file to use in an http-connector SendTask and need to substitute variable values into the payload. I was hoping for a hook to the expression engine Camunda already uses for that purpose.

Look into the code I posted above. You will see you can pass bindings into freemarker. So you can pass the execution variable and then use the expression Lang in freemarker to do what you want.

Thanks Stephen … let me be a little more clear. I want ALL of the Camunda variables to be available, and was hoping to just tie in to the same expression evaluator they use for connector parameters, etc.

I was able to work out my solution by having a task input parameter declared as a freemarker script, and then reading in a template file from the disk. If freemarker is used as a script then it will automatically have access to all of the variables in scope. This isn’t exactly what I was looking for … it ended up better than what I was looking for.

Note that you will have a 4000 character limit on the output of your freemarker script because it is saving it as a local variable on the task as a string

Sorry - I should have scrolled up and read the thread you pointed me to from the top. I see where you tried to create the bindings to ‘execution’, but your notes say that it didn’t work.

Here is working code (Script Task) from 7.10:

var content = "hello ${Zenv} how are you ${ZzipCode} ";

var manager = new javax.script.ScriptEngineManager();
var engine = manager.getEngineByName(“freemarker”);
var bindings = engine.createBindings();


print("\n\nZenv", Zenv);
print(“ZzipCode”, ZzipCode);

var rendered = engine.eval(content, bindings);
print("\nrendered", rendered);

1 Like

Great work. Thanks for sharing.