OL Learn

Skip CSV Header in Post Processor

I have a workflow process which extracts data from PDF and insert into database.
I also want to write a daily csv of all records whose postal code is empty.

I figured I could use a datamapper post processor script and this works fine, except that I don’t know how to skip the CSV header after the first PDF file of the day.

Obviously the first datamapping operation of the day will create a new CSV file with a header if there are records with empty postal codes.

This file needs to be updated throughout the day and a new file should be created every day.

Any ideas?

var fileOut = openTextWriter(“c:\out\empty_postcodes_” + data.records[0].fields.TodaysDate +".csv");
var Labels = ‘Fullname;Company’;
fileOut.write(Labels);
fileOut.newLine();
var str="";
for (var i=0; i < data.records.length;i++){
zip = data.records[i].fields.PostalCode;
if( zip ==’’){
name = data.records[i].fields.FullName;
company = data.records[i].fields.Company;
str = name +’;’ + company;
fileOut.write(str);
fileOut.newLine();
}
}
fileOut.close();

Why not simply have Workflow create the file everyday, with the header? It could simply look if the file already exist. If it does, then it do nothing. If it don’t, it creates it with the header and the Datamapper doesn’t have to handle this. It simply update the file.

This has the added difficulty of using the metadata api in the workflow run script.
I heard metadata api, job infos, and local variables are being deprecated. For instance local variables are now replaced with runtime parameters. I am just trying to build future proof solutions.

So any chance I can make it work in the datamapper? Do methods such as fileexists() work in the datamapper api? and how do i open a file for appending vs creating a new file?

Any ideas?

You don’t need any of that stuff in Workflow for this to work.

All you need in your process that uses the File/folder condition task to check if the file has already been created. If it hasn’t, you add a Create File task that simply contains your list of headers, and then a Send To Folder task to save those headers into a new file.
No metadata, no variables, etc.

And no, metadata, jobinfos and local variables are not being deprecated. Runtime Parameters simply make things easier when interacting with Connect resources.