Hitachi Vantara Pentaho Community Forums
Results 1 to 3 of 3

Thread: If-else Javascript statement

  1. #1

    Default If-else Javascript statement

    Hi All,

    I have two columns "strCellphone" and "strPhone". I want to create a new column "Phone" and Copy values from "strCellphone" but if "strCellphone" is empty, I want to copy values from "strPhone". I tried this with JS and it works on a normal editor but on Pentaho, I am not getting results as expected.

    Here is my JS snippet:

    var phone = strCellphone ;
    if (!strCellphone.length){phone = strPhone;}

    I have also tried various ways of checking null, empty like this one -> if (!strCellphone.length || strCellphone === ' '){phone = strPhone.getString();}

    On Pentaho, The result is always assigned to if "strCellphone" even if it is empty.

    Can you tell me what could be the problem? Thanks!

  2. #2
    Join Date
    Apr 2013


    //If you sure that one of the stream field is filled that should work:
    var phone = null;
    if(strCellphone == null || strCellphone == "") {
    phone = strPhone;
    } else {
    phone = strCellphone;
    //check the results..
    writeToLog("M", "Test phone value: " + phone);
    //and don't forget to output phone variable

  3. #3
    Join Date
    Jun 2012


    var Phone = strCellphone == null ? strPhone : strCellphone;

    PS: When a User Defined Java Expression can solve your problem, don't use JavaScript for performance reasons.
    So long, and thanks for all the fish.

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.