Csv file being created from data mapper

Hi - I found a script on here that works great except it seems to be over writing the data as it is being created. I have approx. 100 pdf files in the input folder. When I run my process everything works fine excepts the csv out put file has only one line of data instead of 100. Below is my code. What am I missing?

var file = openTextWriter(‘c:\4807c\extractData.csv’);

//Add titles
var colNames = Object.keys(data.records[0].fields).filter(function(a){ return a !== ‘ExtraData’;});
file.write(‘"’+colNames.join(‘“,”’)+‘"’);
file.write(‘\n’);

// Add values
for(var i=0;i<data.records.length;i++) {
for(var j=0;j<data.records[i].fields.length;j++) {
file.write(‘"’+ data.records[i].fields[j].toString() + ‘",’);
}
file.write(‘\n’);
}
file.close();

Thank you !

If you run it from the DataMapper application, then you only ever get the current record because that’s the only record that gets processed in the GUI. You’ll have to execute your data mapping operation from Workflow in order to get all records.

ahhhhh - ok makes sense

Thanks