Hitachi Vantara Pentaho Community Forums
Results 1 to 2 of 2

Thread: Create array and use it for in each step

  1. #1

    Default Create array and use it for in each step

    Hello,
    i have to seperate a line of data with the seperator "," and put each value in a array like this:

    for(var i = 0; i < Ausdruck_.getString().length(); i++) {
    if (Ausdruck_.getString().substr(i,1)==",") {
    j++;
    A_Ausdruck[j] = new Object();
    A_Ausdruck[j] = tmp.getString();
    tmp.setValue("");
    i++
    }
    else {
    tmp.setValue(tmp.getString()+Ausdruck_.getString().substr(i,1))
    }
    }
    A_Ersatz = new Array();
    var j=-1;
    tmp.setValue("");
    for(var i = 0; i < Ersatz_.getString().length(); i++) {
    if (Ersatz_.getString().substr(i,1)==",") {
    j++;
    A_Ersatz[j] = new Object();
    A_Ersatz[j] = tmp.getString();
    tmp.setValue("");
    i++
    }
    else {
    tmp.setValue(tmp.getString()+Ersatz_.getString().substr(i,1))
    }
    }
    j++;
    A_Ersatz[j] = new Object();
    A_Ersatz[j] = tmp.getString();
    tmp.setValue("");

    After this, i replace the values, which are stored in the array:

    for (var i=0;i<row.size();i++) {
    var value=row.getValue(i);
    if (value.getTypeDesc().equals("String")) {
    for (var j = 0; j < A_Ausdruck.length; j++) {
    value.replace(A_Ausdruck[j],A_Ersatz[j]);
    }
    }
    }


    It's saved in a javascript-step, so that it is called any time for each row.
    Can i use an array as a global parameter or something like that, so that i have to build the array one time and use it for each row ?

    Thanks !

  2. #2
    Join Date
    May 2006
    Posts
    4,882

    Default

    The scope of each step is each step... you can however store data to be used in next rows. The PDI userguide part on Javascript contains an example on this.

    Regards,
    Sven

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.