Bill,
Assuming you’re using Java 8 or later, the JavaScript engine that is embedded within the JVM and thus used by Camunda BPM is Nashorn. In Nashorn, you can load external JavaScript files using the load
statement, and then you can use those JavaScript files as desired.
I copied “moment.js” into my Spring Boot project directory under “src/main/resources/static/js”, which allows me to load that “moment.js” file using either of the below statements:
load('http://localhost:8080/js/moment.js');
load('./project-name/src/main/resources/static/js/moment.js');
If you aren’t using Spring Boot, you’ll either need to load moment.js from a web server a la the first bullet above or find your user directory and then construct a path that is relative to that. This can be done in Nashorn JavaScript - e.g. within a Camunda BPM Script Task - as shown below:
var System = Java.type('java.lang.System');
var userDir = System.getProperty('user.dir');
print('userDir: ' + userDir);
Once you have that user directory, you can use the load
statement as illustrated in the second bullet point above using the relative path to your “moment.js” file.
By the way, here are the very simple “moment.js” statements that I executed in my process model to test this:
var formattedCurrentDate = moment().format("dddd, MMMM Do YYYY, h:mm:ss a");
print('Formatted current date: ' + formattedCurrentDate);
I hope this helps!
-Ryan