JavaScript
The transform allows multiple scripts in a single transform instance.
The Javascript transform is not an input transform and therefore requires an input stream from the pipeline.
Javascript functions Panel
The Javascript functions panel contains a tree view of scripts, constants, functions, input fields, and output fields as described below.
Double click on any of the scripts, constants, functions or fields to add them to the script.
Transform Scripts
Scripts you have created in this transform.
Transform Constants
A number of pre-defined, static constants that control what happens to the data rows.
To use these constants, you must first set a pipeline_Status variable to CONTINUE_PIPELINE at the beginning of the script, so that the variable assignment is made to the first row being processed. Otherwise, any subsequent assignments to the pipeline_Status variable are ignored.
The available constants are:
SKIP_PIPELINE: Excludes the current row from the output row set and continues processing on the next row.
ERROR_PIPELINE: Excludes the current row from the output row set, generates an error, and any remaining rows are not processed.
CONTINUE_PIPELINE: Includes the current row in the output row set.
ABORT_PIPELINE: Excludes the current row from the output row set, and any remaining rows are not processed, but does not generate an error. (This constant does not display in the transform dialog, but can be used in your script)
Transform Functions
String, numeric, date, logic, special, and file functions you can use in scripts. These included functions are implemented in Java and execute faster than JavaScript functions. Each function has a sample script demonstrating its use. Double-click the function to add it to the Javascript pane. Right-click and choose Sample to add the sample to the Javascript pane.
Input Fields
Input fields for the transform.
Output Fields
Output fields for the transform.
The position at the bottom of the Javascript panel displays the line number and position of the cursor.
The selects the level of JavaScript optimization. The values are:
1: JavaScript runs in interpreted mode.
0: No optimizations are performed.
Script types
You can right-click a tab in the Javascript panel to open a context menu with the following commands:
Add new – Add a new script tab.
Add copy – Add a copy of the existing script in a new tab.
Set Transform Script - Specify the script to execute for each incoming row. Only one tab can be set as a transform script. The first tab is a transform script by default.
Set Start Script - Specify the script to execute before processing the first row.
Set End Script – Specify the script to execute after the last row has been processed.
Remove Script Type - Specify to not execute the script. The script tab is not removed. To remove a script tab, click the Close button (the red “X”) and choose Yes to delete the script tab.
The icon for the script type displays on the tab to denote the type of script on the tab. To rename a script tab, right-click the tab name in the Transform Scripts section of the Javascript functions panel, choose Rename, and enter the new name.
The Fields table contains a list of variables from your script, and enables you to add metadata to the fields, like descriptive names.
Javascript Internal API Objects
You can use the following internal API objects (for reference see the classes in the source):
PipelineName: A String holding the pipeline name
transform: the actual transforms instance for this transform (org.apache.hop.pipeline.transforms.javascript.ScriptValues)
row: The actual instance of the data Object[]
Fields must be added to the rows in the same order to keep the structure of the row coherent.
To add a field, define it as var in the Javascript pane, and add it as a field in the Fields table.
Most values that are assigned in JavaScript are floating point values by default, even if you think you have assigned an integer value. If you are having trouble using == or switch/case on values that you know are integers, use the following constructs:
To filter rows (remove the rows from the output for example) set the pipeline_Status variable as follows:
All rows matching the specified condition are removed from the output.