Pentaho

 View Only

 Field Name with intermittent spaces

E P's profile image
E P posted 02-27-2023 11:44

I have data coming from a CSV feed.

Some field names have interspersed spaces.
Normally you delimit them with backtick, ie `field name`, characters in SQL.
In the Formula transformation you use [field name].
However, neither syntax works in the Modified Javascript Values transformation,
    nor does field%20name, field_x0020_name etc

They reflect correctly in the Input Field list, as can be seen in the screenshot.

How can I reference such field names in the MJSV trnasformation?

Thomas Stutz's profile image
Thomas Stutz

If you have a field that contains a space, you can use that field in a "Modified Java Script Value" step by enclosing the field name in double quotes and square brackets. This will tell Pentaho to treat the entire field name as a single entity, rather than interpreting the space as a separator between separate field names.

Alert(["Date Imported"]);

E P's profile image
E P

Thanks so much for responding Thomas.

However Alert(["Date Imported"]); only prints the literal string "Date Imported".  It does not resolve the field by that name!

Petr Prochazka's profile image
Petr Prochazka

Try eval('Date Imported').

E P's profile image
E P

Thanks Petr, but that also does not resolve the field.

Petr Prochazka's profile image
Petr Prochazka

OK, this works:

//Script here
var i = getInputRowMeta().indexOfValue("Date Imported")
var value = row[i]

If step processes a lot of rows, so it's better define index of fields in start script (this is called only once before first row).

E P's profile image
E P

Ah Petr, you're a superstar... thanks so much.