Hi, I have an xml data file I am working with. In the end, I use this xml for three other reports that I do. However, for this particular one, I need to have a pdf and a csv version of the data. Is it possible to save a copy of the data as a csv file at the end of the workflow?
One way to do it would be from your Datamapper as a post-process script. Since you have accee to the whole data from there, you could code a script that generate a CSV file.
Or you could do it in Workflow using the Create file plugin.
The idea is to split your XML file and then use the Create File plugin. In it, your extract value from your XML file and build your CSV output the way you want it. 1 CSV line (or more) per XML splitted file. Then you output into a folder using the concatenation option of the Send to Folder plugin. Make sure that you use the same file name and that you add a CRLF character between each concatenation.
Hi - I got this to work in workflow using your suggestions above. I am having a few issues with the output not parsing correctly. Plus for this this example I have 188 records, so it takes at least three minutes for it finish the workflow because it has to go through the splitter that many times. Unless I am doing something wrong. I am thinking the most efficient way would be to use a post-script in the datamapper, right? I am not very good with scripts yet. Are there any examples that might help me?
//Define the CSV file
var fileOut = openTextWriter("c:\\out\\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();
In the DataMapper GUI, the post-processing scripts only run for the current record. However, if you execute the data mapping operation from Workflow, then the entire job will be processed.
I just tested it here and the script works just fine.
No the output option doesn’t matter. But you should at least double check how many records ot extracted by the process (if you set the output option to Metadata, use the metadata viewer to see how many documents have been extracted to the parent Group: