Hitachi Vantara Pentaho Community Forums
Results 1 to 5 of 5

Thread: javascript startup script and variables

  1. #1
    Join Date
    Feb 2011
    Posts
    152

    Default javascript startup script and variables

    I have a transformation that has 2 steps in it, get variables followed by a javascript step. In the javascript step I have both a transformation script, and a startup script. When I try to reference field names in the startup script that the get variables step sends it, I get an error:

    Variable not defined.

    However, if I copy the code in the startup script to the transformation script, and comment it out, then everything works. This sounds like a bug to me.

    I submitted this as a bug, but it just got closed saying it is not a bug. Can someone look at this and explain what is going on?

    Here is the bug report I submitted. It has an attached transformation to demonstrate this:

    http://jira.pentaho.com/browse/PDI-13170

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

    Default

    You can't do row processing in a start script.
    Use it for variable declaration and initialization, define functions there, but stay away from field variables.
    That's what I do.
    So long, and thanks for all the fish.

  3. #3
    Join Date
    Feb 2011
    Posts
    152

    Default

    My question is about the behavior that having commented out code in the transformation script allows the startup script to work is what is baffling to me. I don't understand why that would be the case.

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

    Default

    So I failed to see your point - my bad, sorry. You now have my full attention.

    While the start script is definitely compiled and executed before the transform script, putting the used fields into the scripting context is one of the first things done at all.
    The step author tries to identify used fields using a poor man's parser (case insensitive string search) knowingly counting fieldnames found inside of a comment among the used fields.
    While it's not really a bug, the behavior should be documented at least.
    Eventually I would have closed the case, too, since you can easily avoid the side effects of this parser short cut by following my advice from above.
    Curiosity kills the cat ...
    So long, and thanks for all the fish.

  5. #5
    Join Date
    Feb 2011
    Posts
    152

    Default

    Thank you for the good explanation. That is really what I was trying to get at when I filed the bug report.

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.