Hitachi Vantara Pentaho Community Forums
Results 1 to 3 of 3

Thread: Check if a parameter is NULL

  1. #1

    Default Check if a parameter is NULL

    Hi,

    I am setting the default value of a parameter in a transformation as 'null'. And in the modified javascript of that transformation I want to check if the parameter value is null or not. Simple if condition is not working, i.e
    var today = new Date();
    var current_hr=today.getHours();

    var dd = today.getDate();
    var mm = today.getMonth()+1; //January is 0!

    var yyyy = today.getFullYear();
    if(dd<10){dd='0'+dd}
    if(mm<10){mm='0'+mm}
    var today_date =yyyy+'-'+mm+'-'+dd;
    var rep_hour="";
    var man_date_val=getVariable("man_date","");

    if (man_date_val==null)
    {
    var rep_hour=(current_hr*1)-1;
    if(rep_hour <=9)
    {
    hr="0"+rep_hour;
    }
    else
    {
    hr=rep_hour;
    }
    var date_time=today_date+ " " +hr +"%"
    var key_time=today_date+ " " +hr +":00:00";
    }
    else
    {
    date_time=man_date_val;
    var key_time=date_time;
    }

    Here, even if man_date default value is null(defined in settings of the transformation), it is always going to the else condition. Any suggestion or help???

    Thanks in advance.
    Poulomi

  2. #2
    Join Date
    Jun 2012
    Posts
    5,534

    Default

    getVariable() will always return a String.

    The easiest test would be (!man_date_val), I think.
    So long, and thanks for all the fish.

  3. #3
    Join Date
    Nov 2008
    Posts
    777

    Default

    Quote Originally Posted by poulomi View Post
    I am setting the default value of a parameter in a transformation as 'null'.

    var man_date_val=getVariable("man_date","");
    No, you aren't. You are setting it to an empty string. There is a difference.

    Try using this for your test:
    Code:
    if (man_date_val.equals(""))
    {
    ...
    Last edited by darrell.nelson; 01-03-2014 at 10:37 AM.
    pdi-ce-4.4.0-stable
    Java 1.7 (64 bit)
    MySQL 5.6 (64 bit)
    Windows 7 (64 bit)

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.