Hi - I am trying to write a csv file from the postprocessor. I found a script in the [‘Steps](PlanetPress Connect 1.6.1 User Guide Mapping Workflow/Step_types.htm?Highlight=Step properties postprocessor)’ part of the help guide that I thought would be exactly what I needed. I must be missing something because when my file is produced, I only get the labels. I do not get any other data. I have commented out a second loop becasue I was told I needed that becasue I am working with dynamic data. Before I use the second for loop I wanted to get the first one working first. My script is as follows: ( my extraction looks like this table = APVendor and there are a total of 188 records within the table.
var fileOut = openTextWriter(“c:\out\FeeBankSummary.csv”);
var Labels = ‘PayCode,Name,TotalPayable,Adjusted,Totalpaid’;
fileOut.write(Labels);
fileOut.newLine();
//Go through all records to extract the fields value
var str=“”;
for (var i=0; i < data.records[i].length;i++){
//for (var p=0; p < data[i].records.tables.APVendor.fields.length;p++){
var PayCode = data.records[i].tables.APVendor[i].fields["PayCode"];
var Name = data.records[i].tables.APVendor.fields["Name"];
var TotalPayable = data.records[i].tables.APVendor.fields["TotalToVendor"];
var Adjusted = data.records[i].tables.APVendor.fields["TotalAdjustment"];
var TotalPaid = data.records[i].tables.APVendor.fields["TotalAdjustedToVendor"];
str = PayCode +',' + Name + ',' + TotalPayable + ',' + Adjusted + ',' + TotalPaid;
fileOut.write(str);
fileOut.newLine();
}
fileOut.close();
Does anyone have any idea what I am missing?
Thank You !!
Please try the following:
var fileOut = openTextWriter(“c:\out\FeeBankSummary.csv”);
var Labels = ‘PayCode,Name,TotalPayable,Adjusted,Totalpaid’;
fileOut.write(Labels);
fileOut.newLine();
//Go through all records to extract the fields value
//Slice your record into an array and go through all the element of the array
var records = .slice.call(data.records)
records.forEach(function(record) {
//for (var p=0; p < data[i].records.tables.APVendor.fields.length;p++){
var PayCode = record.tables.APVendor.fields["PayCode"];
var Name = record.tables.APVendor.fields["Name"];
var TotalPayable = record.tables.APVendor.fields["TotalToVendor"];
var Adjusted = record.tables.APVendor.fields["TotalAdjustment"];
var TotalPaid = record.tables.APVendor.fields["TotalAdjustedToVendor"];
var str = PayCode + ',' + Name + ',' + TotalPayable + ',' + Adjusted + ',' + TotalPaid;
fileOut.write(str);
fileOut.newLine();
})
fileOut.close();
The problem with your code was this:
for (var i=0; i < data.records[i].length;i++)//wrong
and this:
var PayCode = data.records[i].tables.APVendor[i].fields[“PayCode”];//wrong
It looks like you are trying to loop through the detail table of your record. If so, think 2 loop…one for all record, one for all detail records.
Hi - I’m back at this and still can’t get anything to work. After countless hours/days trying every way possible, I am at a loss. Can anyone help me with the second loop? I have switched to a different approach then above. No matter what I try - I always end up with an undefined of something error. I was using ‘twoRec’ for my second loop attempt. This is where I finally ended up.
var fileOut = openTextWriter(“c:\out\BankSummaryFee.csv”);
var str=, oneRec, twoRec, prop;
// Add Column names as first line in CSV
oneRec = data.records[0];
twoRec = data.records.tables[APVendor];
for (prop in oneRec.fields){
str.push(‘"’+prop+‘"’);
for (prop in twoRec.fields)
str.push(‘"’+prop+‘"’);
}
fileOut.write(str.join(“,”));
fileOut.newLine(); str = ;
// Add all values for all records
for (var i=0; i < data.records.length;i++){
for (var s=0; s < data.records.tables[APVendor].length;i++){
for (prop in oneRec.fields) {
str.push(‘"’+oneRec.fields[prop]+‘"’);
for (prop in twoRec.fields) {
str.push(‘"’+twoRec.fields[prop]+‘"’);
}}
fileOut.write(str.join(“,”));
fileOut.newLine();
str = ;
}
//Close file
fileOut.close();
Thank you
This is very awesome!
Is there a way not to export the ‘ExtraData’ colomn?