External resource problem

I have a situation where we will want to frequently (many times a day) change an external script (a Freemarker script) but not change the workflow that is referencing it. From what I’ve read you must deploy the workflow and the script at the same time. I tried deploying the script separately, but the workflow couldn’t find it.

Do you have any ideas for me? Any workarounds? Do I deploy them together the first time and then redeploy the script? I would hate to make it a classpath resource and constantly change the file in the /lib directory. It seems like I ought to be able to just use a file system path to the script, but I don’t see anyway to do that.

I considered using Javascript to read the file based on path and then running it through Freemarker, but then I have to get all of the variables registered with Freemarker so it can do the substitutions.

Update This didn’t work.
I tried deploying the model and the script file together and they do, indeed, work fine. Then I tried changing the script file and deploying again with deploy-changed-only=true. It deployed the new script file, but the previously deployed workflow is still reading the old script file.

Thanks

See Freemarker Script: Greater than 4000 char, exceeding historic variable instance DB insert

And you can pass the execution object into your freemarker engine as a binding. This is the same way that Camunda does it when using a script task and you can use the “freemarker” as your script type.

If you use JavaScript, you can use the nashorn load("http://....") to load your file and then pass it into the freemarker engine.

I read the thread, but your notes seem to indicate you had problems binding the execution variables to the script engine. Did you solve this (preferably, in Javascript) ? Is it as simple as execution.getVariables() . ??

I did not try it at the time, but you can just do a execution.getVariables(). And that will return a string, object map. Then just pass that map as a binding into freemarker

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();

bindings.putAll(execution.getVariables());

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

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

1 Like

Thanks for sharing