...
Description
On occasion, the question comes back about how to evaluate certain conditions in the "JavaScript" job entry in version 3.x of Pentaho Data IntegrationUse the JavaScript job entry to calculate a boolean expression. The result can be used to determine which step will be executed next. You can use functions, procedure calls, ANDs, ampersands, ORs, EQUALs, etc. The Javascript job entry evaluates and returns a true or false.
Evaluation
The result of a JavaScript job entry is either true or false. In other words, it needs to end with a boolean expression.
...
Code Block |
---|
parent_job.getVariable("INPUT_DIRECTORY").equals("/tmp"); |
The following variables are available for the expression:
Note: Make sure that you specify a step to pick the "lines_input" and other numbers from. Otherwise the values will remain 0. Open the transformation file and do that in the Transformation settings dialog, log tab.
Variable | Description |
---|---|
errors | Number of errors in the previous job entry (long) |
lines_input | Number of rows read from database or file (long) |
lines_output | Number of rows written to database or file (long) |
lines_updated | Number of rows updated in a database table (long) |
lines_read | number of rows read from a previous transformation step (long) |
lines_written | Number of rows written to a next transformation step (long) |
files_retrieved | Number of files retrieved from an FTP server (long) |
exit_status | The exit status of a shell script (integer) |
nr (integer) | The job entry number; increments at every next job entry |
is_windows | use if Pentaho Data Integration runs on Windows (boolean) |
Variables
Here is how you can evaluate the content of a variable string:
parent_job.getVariable("NR_OF_ROWS") == 1000000
Since we have access to the parent_job object, we can also set variables in the parent job this way:
parent_job.setVariable("NR_OF_ROWS", "1000000"); (
Note that the setVariable call can
...
evaluates to false. Put a "true" after it to avoid having the step evaluate to false and throw an error
...
.
For example you can do something like the following to manipulate variables within this job entry:
Code Block |
---|
useDate = parent_job.getVariable("use_date").equals("1");
if (useDate == 0) { //We get to use native java classes as this is using Rhino mocks???
date = new java.util.Date();
date.setDate(date.getDate()-1); //Go back 1 full day
dateFormat = new java.text.SimpleDateFormat("yyyyMMdd");
newDateStr = dateFormat.format(date);
parent_job.setVariable("start_date", newDateStr);
}
true;
|
Previous result
When a job entry finishes, the result of the execution will be a Result object exposed as "previous_result" to the JavaScript engine:
...