I’m attempting to create a postprocessor script which will allow me to turn my XML data into a CSV. I’ve been trying to follow some of the scripts on here, but in order to understand what data I’m working with myself I’ve been trying to simply logger.message(record) or something similar to see what the data is I’m working with… (eventual goal to get to record.fields.someField)
However, my my logger is stating Error running postprocessors( ReferenceError: “record” is not defined. (Postprocessor2#1)).
I’m sure it’s probably user error, but i figured I could access the record in the postprocessor step??
You were close. Use data.records[_index_] to access all records, where _index _goes from 0 to data.records.length-1.
While in the dataMapper, you only ever have access to records[0] since only the current record is “seen” because none of the other records are being written to the database. But at production time, you will have access to all records.
Thank you for your response. It appears what you provided does indeed work. However, my record is COTG XML data, and when it gets to the point of having to write the information for the strings which represent pictures (data:image/jpeg;base64…), the process goes awry. It appears that that string is replaced with the image data and the entire process breaks after that, because it’s including all the information for the image itself rather than the string reference? Or at least that’s what I’m gathering…
That doesn’t give us much to go on… You’d have to tell me what kind of error you’re getting, if any.
The image data is a base64 -encoded string, so that shouldn’t be an issue except that obviously, the resulting CSV field is going to be huuuuuuuuuuuuge… Also, note that the image data contains colons and semi-colons, so you have to make sure to encase all your fields between double quotes if you’re using either ; or : as your CSV field separator.
Finally, what if you skip the Image field in your code that exports the data ? Does the rest of the post-processor run as expected?
It appears you are correct and my issue is from not properly escaping characters which are mapped into the data, like character returns and double quotes. With some tweaking I believe I’ll be able to remedy.