Is it possible to use an xml data file in workflow and then save a copy as csv?

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?

Thank you

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?

Thank You !!

//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();

Hi,

This script works but only for the first record! Should it not loop through all the records?

Thanks
Joe

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.

Hi Phil,

Yes, I did think that might be the case so tried running the DataMapper through Workflow but got the same result (one record).

Feel I’m so close, any help would be greatly appreciated.

Does it matter which output option I choose in the DataMapper?

Thanks,

Joe

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:

Which matches the output generated by the post-processor script.

Which record is output to your CSV file? Is it the first one, the last one, or some random record?

Hi Phil,

To answer your question it’s the first record which is why I thought it might be an issue with the loop.

I’ll check the Metadata now to see how many record it’s reporting.

Thanks

Hi Phil,

I checked the number of records extracted after the DataMapper and it’s just one. It should be 7 (see last image).

It okay to have an csv input file?

If you have one record per CSV line, you should set your document boundaries accordingly: