I have been using a Postprocessor script to write fields extracted from PDF data sources to CSV files for half a year now, but I have run into a strange issue with the latest DataMapper. The fields in the CSV file are not written in the same order they appear in the DataMapper.
var fileOut = openTextWriter("D:\\Shared Folders\\Working Ignite\\2. Utilities\\Oakdale\\oakdaleaddressdata.csv","UTF-8");
var str=[],headers=[],oneRec;
// Add all values for all records
for (var i=0;i<data.records.length;i++){
oneRec = data.records[i];
for (var prop in oneRec.fields) {
// Add field names as headers
if(headers){
headers.push('"'+prop+'"');
}
str.push('"'+oneRec.fields[prop]+'"');
}
if(headers) {
fileOut.write(headers.join(","));
fileOut.newLine();
headers=null;
}
fileOut.write(str.join(","));
fileOut.newLine();
str = [];
}
//Close file
fileOut.close();
@rdaneel72, I’m not sure if you’ve already opened a ticket for this but you may want to check what the result of the script is by logging the lines written to the CSV file in the Data Mapper engine logs. This can be achieved by making the following adjustments, for example.
var lines = [];
for (var i = 0; i < data.records.length; i++) { /* ... */ }