Hitachi Vantara Pentaho Community Forums
Results 1 to 7 of 7

Thread: Javascript: Fill empty records

  1. #1
    Join Date
    Apr 2008
    Posts
    1,771

    Exclamation Javascript: Fill empty records

    Hi.
    Need some help with JS.

    My text file has two fields:
    1. PCDPS: String
    2. TempURN: Integer (created using Sequence Step)

    Example of data:
    PCDPS, TempURN
    PE1 2UX,1
    PE2 3UX,2
    ,3
    ,4
    PE3 4UX,5

    As you can see, some records do not have any data for PCDPS.
    Using a javascript, I want to fill in those empty records using the value from the TempURN field.

    The end result should be:
    PCDPS, TempURN
    PE1 2UX,1
    PE2 3UX,2
    3,3
    4,4
    PE3 4UX,5

    I use the following script:
    if (PCDPS.value==null) {
    PCDPS.value == num2str(TempUrn);
    }

    If I test the script, I do not have any error, but my ouyput file is like the original.
    Any suggestion, please?

    Thanks,
    Mick

  2. #2
    Join Date
    May 2006
    Posts
    4,882

    Default

    Assignment is done using '=' not '=='

    But probably it's easier to attach your transformation.

    Regards,
    Sven

  3. #3
    Join Date
    Apr 2008
    Posts
    1,771

    Unhappy Still not working

    Hi Sven,

    I have changed my script with your suggestion:

    if (PCDPS.value==null) {
    PCDPS.value = num2str(TempUrn);
    }

    Now every record is populated with "TempUrn" data.
    It seems that the IF is not working.

    Am I doing some very basic error in writing my IF?

    Thanks.

    Mick

  4. #4
    Join Date
    Feb 2009
    Posts
    296

    Default

    Just a suggestion:
    use the "Filter rows" step and the "Calculator" step to do the job.
    Fabian,
    doing ETL with his hands bound on his back

  5. #5
    Join Date
    Apr 2008
    Posts
    1,771

    Default

    Hi Fabian.
    It sounds like a good idea!

    But how would you merge the data back without creating 2 phisical output files?

    Mick

  6. #6
    Join Date
    May 2006
    Posts
    4,882

    Default

    For the '==' not working in the if... it depends... try using equals() to compare strings. Normally you are able to use == to compare strings in javascript, but because of the integration of javascript in PDI sometimes you mix java strings with javascript strings which lead to this kind of thing.

    Regards,
    Sven

  7. #7
    Join Date
    Apr 2008
    Posts
    1,771

    Default Filtering records

    Hi Fabian, Sven.
    Thanks for your help.

    At the end I decided to use the "Filter records" step.
    It uses 3 more steps then the original transformation, but it works fine.

    Mick

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.