Hitachi Vantara Pentaho Community Forums
Results 1 to 3 of 3

Thread: Problem with Modified Java Script Value

  1. #1
    Join Date
    Feb 2015
    Posts
    22

    Default Problem with Modified Java Script Value

    Hi,

    I have a Modified J S Value with the following code:

    Code:
    if(DIF_2010_1 == DIF_2010_2){
    var FLAG_2010 = 1;
    }
    Is there something wrong? All the rows, including rows that does not satisfy the condition gets FLAG_2010 = 1.

    Also, the code bellow does not work too. In the following code no row gets FLAG_2010 = 1.

    Code:
    if(VL_M3002069==VL_M3002069_1 && VL_M3002069==VL_M3002069_2){
    var FLAG_2069 = 1;
    }
    else
    {
    var FLAG_2069 = 0;
    }
    The fields VL_M... _2 and _1 comes from LEAD rows with analytics query.

    Thanks!

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

    Default

    I would use Filter Rows and Set Constants steps for these.
    Filter Rows (DIF_2010_1 is equal to <field> DIF_2010_2) -- True, "Add Constant" FLAG_2010=1; False "Add Constant" FLAG_2010=1 both steps merge onto
    Filter Rows (Complex, two comparison joined by AND) -- True, "Add Constant" FLAG_2069=1; False "Add Constant" FLAG_2069=1 both steps merge onto dummy, which connects to the rest of your processing.

    But if you MUST use MJSV, make sure you initialize your variables for each row, or they will carry across rows. This is *NOT* a bug, it's useful for other things.

    Are the values that you are comparing strings? If so, you can't use the == operator, you have to use a .equals() method.

  3. #3
    Join Date
    Feb 2015
    Posts
    22

    Default

    Quote Originally Posted by gutlez View Post
    I would use Filter Rows and Set Constants steps for these.
    Filter Rows (DIF_2010_1 is equal to <field> DIF_2010_2) -- True, "Add Constant" FLAG_2010=1; False "Add Constant" FLAG_2010=1 both steps merge onto
    Filter Rows (Complex, two comparison joined by AND) -- True, "Add Constant" FLAG_2069=1; False "Add Constant" FLAG_2069=1 both steps merge onto dummy, which connects to the rest of your processing.

    But if you MUST use MJSV, make sure you initialize your variables for each row, or they will carry across rows. This is *NOT* a bug, it's useful for other things.

    Are the values that you are comparing strings? If so, you can't use the == operator, you have to use a .equals() method.
    Nice! I guess I gonna do the way you said. About the initialization the variables for each row, you mean the "var VariableName"? The values that I'm comparing are Numbers, but I'm gonna try with .equals() to ensure that the problem is not the "==".

    Thank you very much!
    Last edited by rafaelcampos; 03-10-2016 at 09:32 PM.

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.