Added by Matt Casters, last edited by Johann Brel on May 22, 2008  (view change)

Labels:

Enter labels to add to this page:
Wait Image 
Looking for a label? Just start typing.


Introduction 

On occasion, the question comes back about how to evaluate certain conditions in the "JavaScript" job entry in version 3.x of Pentaho Data Integration.

Evaluation

The result of a JavaScript job entry is either true or false.  In other words, it needs to end with a boolean expression.

Here are a few possible evaluations to end your script with :

lines_input > 100

or

true

or

parent_job.getVariable("INPUT_DIRECTORY").equals("/tmp");






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 (always?) evaluates to false. Put a "true" after it to avoid having the step evaluate to false and throw an error) 

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:

Expression Alternative Data type
Meaning
previous_result.getResult()
boolean
true if the previous job entry was executed successfully, false if there was some error.
previous_result.getExitStatus()
exit_status int
exit status of previous shell script job entry
previous_result.getEntryNr()
nr int
The entry number is increased every time a job entry is executed.
previous_result.getNrErrors() errors long
the number of errors, also available as variable "errors"
previous_result.getNrLinesInput() lines_input long
The number of rows read from a file or database
previous_result.getNrLinesOutput() lines_output long
The number of rows written to a file or database
previous_result.getNrLinesRead() lines_read long
The number of rows read from previous steps
previous_result.getNrLinesUpdated() lines_updated long
The number of rows updated in a file or database
previous_result.getNrLinesWritten() lines_written
long
The number of rows written to next step
previous_result.getNrLinesDeleted() lines_deleted
long The number of deleted rows
previous_result.getNrLinesRejected() lines_rejected long
The number of rows rejected and passed to another step via error handling
previous_result.getRows()
List<RowMetaAndData> The result rows, see also below.
previous_result.isStopped()   boolean
Flag to signal if the previous previous job entry stopped or not.
previous_result.getResultFilesList()   List<ResultFile>
The list of all the files used in the previous job entry (or entries)
previous_result.getNrFilesRetrieved() files_retrieved
int
The number of files retrieved from FTP, SFTP, etc.

Platform

 
We also expose a variable called "is_windows" to help you make platform specific choices

rows

 
The "rows" variable we expose to JavaScript helps you evaluate the result rows you passed to the next job entry using the "Copy rows to result" step.
Here is an example script on how to use this array:
 

var firstRow = rows[0];

firstRow.getString("name", "").equals("Foo")

 This script will follow the green job hop is the expression evaluates to true.  This happens if field "name" contains String "Foo".

Make sure that you specify a step to pick the "lines_input" and other numbers from otherwise the values will remain 0 for the all eternity. Open the transformation file and Do that in the Transformation settings dialog , log tab.

Zokt said so.

Posted by Anonymous at Oct 06, 2008 06:29