title: Change field value / variable during processing in Pentaho
body: <p>Given input:</p>
  
  <pre><code>PAYLOAD|ROWNUM|TYPE
  1234   |     1|user
  aaa    |     2|data
  bbb    |     3|data
  ccc    |     4|data
  5678   |     5|user
  ddd    |     6|data
  aaa    |     7|data
  </code></pre>
  
  <p>The result should look like:</p>
  
  <pre><code>USER|DATA
  1234|aaa
  1234|bbb
  1234|ccc
  5678|ddd
  5678|aaa
  </code></pre>
  
  <p>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.</p>
  
  <p>The code I tried uses one MJSV step</p>
  
  <pre><code>var varNameUserId = "var.user_id";
  
  if(TYPE == "user") {
    setVariable(varNameUserId, PAYLOAD, "r");
  }
  </code></pre>
  
  <p>And in another MJSV step</p>
  
  <pre><code>var varNameUserId = "var.user_id";
  var varUserId = getVariable(varNameUserId, "xxx");
  
  var USER = varUserId;
  </code></pre>
  
  <p>Finally, a "Text Output" step writes all to a file.</p>
  
  <p>Any hints/ideas/suggestions?</p>