PDA

View Full Version : JavaScript tips...



MattCasters
02-08-2006, 11:29 PM
I'll put these in the FAQ later on, but for now I'll post them on the forum: 2 questions and answers concerning JavaScript & Kettle:

PROBLEM 1:

I am not able to use some java script functions which is not in the list
given in the documentation (kettle) like Split and lot of other string related functions;

ANSWER 1:

You first need to get the java primitive value with:

getString() : java.lang.String
getDate(): java.lang.Date
getNumber: double
getBigNumber: BigDecimal
getBoolean: boolean

On these java primitives you can use java methods like split, etc.


PROBLEM 2

A. I am not getting any defined_variable which returns the total number of columns that are coming from the immediate step.
B. In java script I want to access data value not by using fieldname.getValue() but by functions like row.Fields(field_index)


ANSWER 2

there is a special defined variable called “row” so this would do the trick for problems 2A and 2B:

var fields = row.size();
var field = row.getValue(field_index);

Again, row is be.ibridge.kettle.core.Row, so you can use any of the methods available in the Row API.
The API is available for download on http://kettle.javaforge.com

Kind regards,

Matt