Hitachi Vantara Pentaho Community Forums
Results 1 to 5 of 5

Thread: questions regarding modified javascript value and java

  1. #1
    Join Date
    Oct 2007
    Posts
    7

    Default questions regarding modified javascript value and java

    ok, i am importing a fixed width file and then i need to parse some data from a comments field. I choose to use Modified Javascript value to parse the field up and create a new variable/field.

    In the comments field i am looking for a string of 6 digits between brakets [] (ie [123456] ). the comments field contains other data which am not concerned about. in my JS code i am using a combo of SubStr and IndexOf to get the string from the field however it doesnt always work. it works when my commetns filed starts like this "[123456] some
    other text" but will not get the digits if the comments field is like this "some other text [123456]". i am not sure what is causing the problem. the code is posted below

    Code:
    if (indexOf(SpecialOrderCustomerHeaderNotes.getString(),"[") >= 0) { var WebOrderID; WebOrderID = substr(SpecialOrderCustomerHeaderNotes.getString(),indexOf(SpecialOrderCustomerHeaderNotes.getString(),"[") + 1,7); } else { var WebOrderID; WebOrderID = ''
    }


    Sample data
    "[123456] STA some other data" - this will return the digits 123456
    STA [123456] some other data" - usually returns just 12

    i need to be able to pick out the number between the digits regardless of location in the comments string.

    can anyone lend a hand?
    rb

    Last edited by MattCasters; 10-26-2007 at 05:05 PM. Reason: made code readeable

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

    Default

    I know this one ... what is the version of PDI you're using?

    Regards,
    Sven

  3. #3
    Join Date
    Oct 2007
    Posts
    7

    Default

    i am using 2.5.2.

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

    Default

    In your version substr in modified javascript uses as last argument the absolute end, not the length. The regular javascript step uses length. Since in v3.0 only the modified javascript survives and "length" is more compatible with regular javascript the modified javascript in v3.0 also uses length as last parameter.

    Regards,
    Sven

  5. #5
    Join Date
    Oct 2007
    Posts
    7

    Default

    sven, that was it. i went back to 3.0 and the code worked great. thanks.

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.