Hitachi Vantara Pentaho Community Forums
Results 1 to 7 of 7

Thread: Scripting- Java script with "contains" Function

  1. #1
    Join Date
    Dec 2012
    Posts
    13

    Default Scripting- Java script with "contains" Function

    Hows it going guys! Happy New Years to you all! I have a quick question that I hope someone can help. I never learned java so im not good at writing java script. I taught myself the basics but this question would not be under the basics of java

    Question:
    I have 2 column of data that I need to make a simple "IF Statement" script.

    Column 1 contains text: For example "EUSA", "NASA", "AFSA", "EUAF", and etc. (one text per row)
    Column 2 contains text: For example "ITCL", "USPE", "USIT","BRCL", and etc. (one text per row)

    My two "IF Statements" would need to be:
    Column 1 must be equal to "EUSA"
    and
    Column 2 must contain "CL" within the text. EX) "USCL" or "ARCL"

    If these both statements are true then bring me back a new variable called TEST with this text in that column "EUCL" if false then bring back "BLANK"

    This is my script so far: I've gotten the first part of the script down but need help with a "contain" function.

    var TEST

    if(Column1.getString()=="EUSA" && **){TEST = "EUCL"}
    else{TEST = "BLANK"}


    Im guessing the ** needs to be something like Column.2.contains "CL"? I cant find it anywhere on the internet and i have a massive headache now

    I would really appreciate your help! Thank you! Kettle on!

  2. #2
    Join Date
    Nov 2008
    Posts
    271

    Default

    Quote Originally Posted by simonlelo View Post
    Im guessing the ** needs to be something like Column.2.contains "CL"? I cant find it anywhere on the internet and i have a massive headache now
    Yep, that's the common effect of abusing javascript.
    Anyway, I can prescribe you as follows
    Code:
    if(Column1 == "EUSA" && Column2.indexOf("CL") != -1){...}
    Also be informed that this kind of illness can be cured by a mix of filter rows and add constant steps.

    Take care.
    Andrea Torre
    twitter: @andtorg

    join the community on ##pentaho - a freenode irc channel

  3. #3
    Join Date
    Apr 2008
    Posts
    4,696

    Default

    Quote Originally Posted by simonlelo View Post
    I never learned java so im not good at writing java script. I taught myself the basics but this question would not be under the basics of java
    Java and JavaScript share very very little outside of the word in their names.

    Other than that, follow Andrea's suggestions... They will get you far.
    Avoid the Modified JavaScript Value step as much as you can for now. There will be some times where it's necessary, but there's lots of other ways to do things in PDI.
    **THIS IS A SIGNATURE - IT GETS POSTED ON (ALMOST) EVERY POST**
    I'm no expert.
    Take my comments at your own risk.

    PDI user since PDI 3.1
    PDI on Windows 7 & Linux

    Please keep in mind (and this may not apply to this thread):
    No forum member is going to do your work for you. We will help you sort out how to do a specific part of the work, as best we can, in the timelines that our work will allow us.
    Signature Updated: 2014-06-30

  4. #4
    Join Date
    Dec 2012
    Posts
    13

    Default

    Thank you Andrea and gutlez for your help, i really appreciate it!!
    I stumbled upon kettle/pentaho from my co workers that left the company a while back and they were just begining to teach me the basics of this beautiful and simple program. Now im stuck with learning the rest of the program on my own in which I don't mind the challenge! You guys might get this alot but is there a online class of some sort in which i can enroll to learn more about his program? im pretty sure this would make my kettles more efficient by using less steps!

  5. #5
    Join Date
    Nov 2008
    Posts
    271

    Default

    np, I had the same headaches a few years ago (still have sometimes, though).
    I'm not aware of online classes. However there is a great deal of material out there, just google it and you will find some valuable blogs. Also this forum is precious. I have found many answers here.

    If you are looking for a comprehensive, well-organized source, I would recommend this book.
    Andrea Torre
    twitter: @andtorg

    join the community on ##pentaho - a freenode irc channel

  6. #6
    Join Date
    Dec 2012
    Posts
    13

    Default

    Andrea thanks for the book! I'm thinking of getting it to see if i learn more tips and tricks! I noticed it was written in 2010, is there any other books that are more up to date with the new functions within the layout of kettle? i heard that kettle has improved tremendous. If not then i will most certainly get this book. Thanks for the recommendation! I really appreciated it!

    I will most certainly come back to this forum if and when i have a headache of not figuring it out on my own or cant find it online! Now i must kettle on!

  7. #7
    Join Date
    Apr 2008
    Posts
    4,696

    Default

    **THIS IS A SIGNATURE - IT GETS POSTED ON (ALMOST) EVERY POST**
    I'm no expert.
    Take my comments at your own risk.

    PDI user since PDI 3.1
    PDI on Windows 7 & Linux

    Please keep in mind (and this may not apply to this thread):
    No forum member is going to do your work for you. We will help you sort out how to do a specific part of the work, as best we can, in the timelines that our work will allow us.
    Signature Updated: 2014-06-30

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.