javascript - Pentaho - Trim Spaces Dynamically - Stack Overflow

admin2025-05-02  0

Bit of a pentaho rookie so let me know if this does not make sense / is not possible:

I am trying to export the contents of a table from my database to a .csv where the columns can change overtime.

Currently, I am using a 'Table input' step followed by a 'Text file output step'. This works to export the file, however it exports the entire field of each column in the select statement:

What I expect in the ID column (10): 'ABCD'

What I am getting in my current setup for ID column (10): 'ABCD______'

How can I trim the fields dynamically based on the output of the select statement?

I have tried using a 'Modified JavaScript value' step so far but I'm not 100% sure how this interacts with it all and hasn't seemed to work as it cannot recognise the rows.

var fieldNames = getInputRowMeta().getFieldNames(); // Get field names dynamically

for (var i = 0; i < fieldNames.length; i++) {
    var fieldName = fieldNames[i];  // Get the field name
    var fieldValue = get(fieldName); // Get the value of the field

    if (typeof fieldValue === 'string') {
        // Apply transformation (e.g., trimming)
        set(fieldName, fieldValue.trim());  // Set the modified value back
    }
}
转载请注明原文地址:http://anycun.com/QandA/1746137368a92090.html