Hitachi Vantara Pentaho Community Forums
Results 1 to 3 of 3

Thread: Javascript Step-- Export as text file one line

  1. #1

    Default Javascript Step-- Export as text file one line

    Hi guys

    My current streams has multiple fields and currently output results to one line flat file with a 3 characters delimiter using the following script:

    function add(a,x) {
    if (x==null) {
    return a + "#*#";
    }
    else {
    return a + "#*#" + x
    }
    }

    var line=null;

    line = add(line,FIELD_NAME_1);
    line = add(line,FIELD_NAME_n);

    Question is how do I make FIELD_NAME_1-5 on the first line, and FIELD_NAME_6 onwards on the second line?

    ps. js beginner

    Looking forward. Thanks!

  2. #2
    Join Date
    Mar 2006
    Posts
    170

    Cool HI

    Hey ...

    I think you need to add a counter variable that is scoped/created outside your function then you should increase it everytime you append a "FIELD_NAME_*" to the line, then do acheck to see if you have enough things on that line. If you do start a New line by appending a newline char to your string. Not sure if the syntax is 100% but you should get the idea from this pseudo-code.

    var counter;

    function add(a,x) {
    if (x==null) {
    return a + "#*#";
    counter++;
    }
    else {
    if(counter > 5){
    return a + "#*#" + x + "\n"; //append newline or carriage return char depending on what OS you are working with
    counter = 0; //reset the counter if you are wanting 5 "things per line", otherwise adjust to a suitable value
    }else
    {
    return a + "#*#" + x;
    counter++;
    }
    }
    }

    Hope that helps

    Kent

  3. #3

    Default

    thanks!

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.