I am on PDI 7.0 and have a "Modified Java Script Value" step inside a transformation as below:
var numberOfDays = 100;
Alert(numberOfDays);
setVariable("NUMBER_OF_DAYS", numberOfDays, "r");
Alert(getVariable("NUMBER_OF_DAYS", ""));
However, when I run the transformation, the first Alert correctly throws 100, but the next Alert is blank (meaning the variable is not set).
What is wrong here?
As a rule of thumb, you should never set a variable and read it within the same transformation.
See a warning that pops up in Spoon when setting up Set Variables
step:
That said, what you could do, if you really insist on setting this via Java Script is the following design:
where
1) Set variable transformation is used to set the value:
var numberOfDays = 100;
Alert(numberOfDays);
setVariable("NUMBER_OF_DAYS", numberOfDays, "r");
2) Get variable transformatoin only reads it
Alert(getVariable("NUMBER_OF_DAYS", ""));
Both transformations use the same steps, but they have separate task.