Customer Portal

Nulling all blank attributes

Comments 1

  • Avatar
    avackova
    0
    Comment actions Permalink
    Hello,
    unfortunately it is not possible in CTL, because the language doesn't support iteration over record's fields. But it can be written really easy in java:
    import org.jetel.component.DataRecordTransform;
    import org.jetel.data.DataField;
    import org.jetel.data.DataRecord;
    import org.jetel.exception.TransformException;
    import org.jetel.metadata.DataFieldMetadata;
    import org.jetel.util.string.StringUtils;


    public class NullBlankValues extends DataRecordTransform {

    @Override
    public int transform(DataRecord[] arg0, DataRecord[] arg1)
    throws TransformException {
    arg1[0].copyFieldsByName(arg0[0]);
    DataField currentField;
    for (int i = 0; i < arg1[0].getNumFields(); i++) {
    currentField = arg1[0].getField(i);
    if (currentField.getType() == DataFieldMetadata.STRING_FIELD && StringUtils.isEmpty((CharSequence) currentField.getValue())) {
    currentField.setNull(true);
    }
    }
    return 0;
    }

    }


    By the way: how do you get these blank values? If you read them from the file it's just enough to set trim attribute on DataReader to true.

Please sign in to leave a comment.