I am exporting data using the datamapper postprocessor script. This seems to be fine except it outputs to what seems to be a default location and filename.
I have defined:
var fileOut = openTextWriter(“C:\Source\Test.csv”);
however the file gets output to ‘C:\OUT’ with a .dat file having the system filename. Can anyone point me in the right direction as to where I am going wrong?
Below is the code I’m using, might be helpful for you. (Thanks to either Phil or Rod). I too could not output to the source folder either but any other folder worked fine. Then I noticed that I had a process running that was actually picking up the file before I got there. This might not be the case for you though but worth a mention. Also try using lowercase for the drive letter.
//Define the CSV file
var fileOut = openTextWriter(“c:\source\invoiceInfos.csv”);
var fieldCounter = 0;
//If you want the first line of the CSV file to have the field name as headers
for (field in data.records[0].fields)
{
if(fieldCounter > 0)
{
fileOut.write(‘,"’+field+‘"’);
} else
{
fileOut.write(‘"’+field+‘"’);
}
fieldCounter++;
}
fileOut.newLine();
//To add all field values to the CSV file.
for (var i = 0; i < data.records.length; i++)
{
fieldCounter = 0;
for (field in data.records[i].fields)
{
if(fieldCounter > 0)
{
fileOut.write(‘,"’+data.records[i].fields[field]+‘"’);
} else
{
fileOut.write(‘"’+data.records[i].fields[field]+‘"’);
}
fieldCounter++;
}
fileOut.newLine();
}
//Close the CSV file
fileOut.close();