Overview
Etlworks allows you to build advanced data integration flows without writing any code.
However, scripting is often the most efficient way to implement logic such as:
-
Processing files in loops
-
Calculating values on the fly
-
Applying business rules
-
Validating data
-
Controlling conditions inside nested flows
-
Building dynamic SQL
-
Performing advanced transformations
JavaScript is the default and recommended scripting language in Etlworks. It is fully integrated with the ETL engine and provides complete access to Etlworks Java APIs, core Java classes, collections, utilities, and your own custom Java libraries.
Python can be used as well, but it is intended only for lightweight inline scripts.
For executing full Python programs with packages, use the flow Execute Script Local or Remote via SSH.
Rear more about using Python in Etlworks.
JavaScript engine in Etlworks
Etlworks uses Nashorn, the JavaScript engine embedded in the Java Virtual Machine.
Nashorn supports:
-
Standard JavaScript syntax
-
Access to all Java classes
-
Direct interaction with Etlworks internals
-
Combining JavaScript and Java code in the same script
Recommended tutorials:
-
Nashorn Tutorial: https://www.tutorialspoint.com/nashorn
-
Oracle Nashorn Overview: https://docs.oracle.com/javase/8/docs/technotes/guides/scripting/nashorn/
Where JavaScript can be used
JavaScript scripting is available throughout Etlworks:
-
Execute JavaScript or Python flow
-
Mapping, for calculating field values
-
Before row, after row, and for each row scripting transformations
-
Conditions and loop conditions in Nested flows
-
Execute before and Execute on Exception blocks
-
Dynamic SQL, function parameters, and many advanced configuration fields
JavaScript is the first-class scripting language in Etlworks and is always recommended unless you specifically need Python syntax.
How to write JavaScript code
Wherever you see a scripting text area:
-
Click Open in Editor.
-
Ensure JavaScript is selected as the language.
-
Write your script.
The editor supports syntax highlighting, indentation, and full-screen mode.
Accessing Java classes from JavaScript
One of the biggest advantages of Nashorn is the ability to directly import and use Java classes.
Importing Java packages
Use the standard Java type resolution:
var ArrayList = Java.type("java.util.ArrayList");
var Utils = Java.type("com.toolsverse.util.Utils");
var Collector = Java.type("com.toolsverse.etl.core.collector.Collector");
Or alternatively
importPackage(java.util);
importPackage(com.toolsverse.util);
importPackage(com.toolsverse.etl.core.collector);
Once imported, Java classes behave almost the same as JavaScript objects. You can mix Java and JavaScript freely.
Example:
var list = new ArrayList();
list.add("value1");
list.add("value2");
value = list.size(); // returns 2
Returning values from JavaScript
Assign to the value variable in the last line
value = firstName + " " + lastName;
Rely on the last evaluated expression
firstName + " " + lastName;
The final expression of the script becomes the result automatically.
Loading external JavaScript libraries
You can load external JS libraries at runtime using load:
// Load from a URL
load("https://example.com/scripts/utility.js");
// Load from the local file system
load("file:///opt/scripts/functions.js");
Using external Java libraries
You can add your own Java libraries and call them directly from JavaScript.
How to install Java libraries in a self-hosted Etlworks instance
-
Copy the JAR file into TOMCAT_HOME/lib.
-
Restart Tomcat.
-
Import the classes in JavaScript:
var CustomClass = Java.type("com.mycompany.CustomClass");
Hosted Etlworks
Contact support@etlworks.com to upload custom libraries.
Best practices for JavaScript in Etlworks
-
Prefer JavaScript over Python for inline logic
-
Import Java classes only when needed
-
Keep functions modular and reusable
-
Always initialize variables explicitly
-
Use flow variables to avoid hardcoding
-
In mapping, keep expressions small and readable
-
For heavy computation, move logic to a dedicated Execute Script flow
When not to use JavaScript
Use JavaScript for inline logic.
Do not use JavaScript for:
-
Full ETL pipelines
-
Large data processing
-
Complex Python replacements
-
Anything requiring Python packages like pandas or numpy
Execute Script Local or Remote via SSH
Read how to Execute Script Local or Remote via SSH
This flow supports:
-
Python 3
-
pip packages
-
Node
-
Bash
-
PowerShell
-
Docker
-
Cloud CLIs
-
SQL CLIs
-
Local and remote execution