Converting CSV to Fixed Length

Hi All, some of the kit we use here requires a fixed length data file to be created. What would be best practice to create this through Workflow or a Datamapper? Thanks

Your best bet would be a script.

If the file are not too big, you could load it all up in memory, scan all records and determine the maximum lenght for each fields.
Then output your fixed length file.

If the file are quite big, then you could first read all records and keep in memeory the max width for each and then reread the file while outputting your fixed lenght one.

Your script could be added to the post-processing steps in the DataMapper. You would therefore have access to all the extracted records immediately after the data mapping is complete, so you wouldn’t have to transfer all of the record data back to Workflow. That would probably be the most efficient method.

This older post shows how to create a csv file from inside a post-processing script.
You would simply have to modify the script to output fixed-length fields as in this example, where the content of a field is padded with spaces until the length reaches 30:

let company = ( data.records[i].fields.Company+" ".repeat(30) ).slice(1,30);

Thanks both for the quick replies and suggestions. I have it in a postprocessor with .padEnd() on each field - seems to be working. Will try with your suggestion as well to see which is quicker :slight_smile: