Hitachi Vantara Pentaho Community Forums
Results 1 to 2 of 2

Thread: Altering String with JavaScript

  1. #1
    Join Date
    Sep 2005
    Posts
    1,403

    Default Altering String with JavaScript

    Hello,


    I load data from a text file, which works pretty well. One field contains a number in the format "+000012,4567", which is not correct (Oracle doesnÂ't like the "+"). I load this field as a string, but now I want to



    1. eliminate the "+" from the string and
    2. convert the string to a number.



    I found the javascript function "replace", but what I do not know is how to use the "Java Script Value"-Transform-Step. How can I assign the value of a field to a java script variable, how can I write the result back to the fiel? Maybe a screenshot would help me most.



    Before using spoon I was used to work with external tables. A replace function could easily be integrated in the external table DDL.



    I would be very thankful if you could help me with this problem.



    Thx in advance.



    Dominik

  2. #2
    Join Date
    Nov 1999
    Posts
    9,729

    Default RE: Altering String with JavaScript

    Hi Dominik,

    You can do it directly in Text File Input by adding the + to the format mask, in your case:

    '+'000000.0000

    or perhaps '+'#.# will also work.

    As for the replace function:

    field.replace("+", "") would do the trick. The value is changed directly on the field value.
    For more information on JavaScript, see the Weekly Kettle Tip on JavaScrip from a few weeks ago on this very forum.

    HTH,

    Matt

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.