Given input:
PAYLOAD|ROWNUM|TYPE
1234 | 1|user
aaa | 2|data
bbb | 3|data
ccc | 4|data
5678 | 5|user
ddd | 6|data
aaa | 7|data
The result should look like:
USER|DATA
1234|aaa
1234|bbb
1234|ccc
5678|ddd
5678|aaa
I've already tried to put the values into (global) variables defined in an outer job, but to no avail. The value in "USER" field will change several times in the file.
The code I tried uses one MJSV step
var varNameUserId = "var.user_id";
if(TYPE == "user") {
setVariable(varNameUserId, PAYLOAD, "r");
}
And in another MJSV step
var varNameUserId = "var.user_id";
var varUserId = getVariable(varNameUserId, "xxx");
var USER = varUserId;
Finally, a "Text Output" step writes all to a file.
Any hints/ideas/suggestions?
(Tested using Kettle 5.0.1)
I leave out ROWNUMBER as it is irrelevant to your question.
Don't forget to register parameter named "currUser" in transformation settings.
The last step also removes column TYPE.
code of JS step:
if(TYPE == "data") {
USER = getVariable("currUser",0);
} else {
USER = PAYLOAD;
setVariable("currUser",PAYLOAD,"p");
}
settings of JS step:
From data grid content to execution results: