-
Running on Mirth 3.5.2 In the preprocessor I'm validating the CSV file. I simply read the first line and split it using the semi-colon (;) as delimiter. Every day the message processing fails (my validation in the preprocessor script fails). Any idea why? The only strange thing I noticed: for some reason the provided CSV file starts with a question mark (so it's the first character of the first header column). Here's the script: // Modify the message variable below to pre process data
// new line character
const NEWLINE = '\n';
// field delimiter
const DELIM = ';';
// expected columns and headers
// in case you wonder: for some reason the provided CSV file starts with a question mark
var COLS = '?foo;bar;spam;eggs'.split(DELIM);
try {
// get 1st line = header
var header = message.toString().split(NEWLINE)[0];
// get columns
var fields = header.split(DELIM);
// validate number of columns
if(fields.length != COLS.length) {
throw new Error('Number of CSV file columns: ' + fields.length.toString() + ' (expected: ' + COLS.length.toString() + ')');
}
// validate fields names in header line
fields.forEach(function(item, i) {
logger.debug("i: " + i + " / COLS[i]: " + COLS[i].trim().toLowerCase() + " / item: " + item.trim().toLowerCase());
if(COLS[i].trim().toLowerCase() != item.trim().toLowerCase()) throw new Error('Invalid CSV file header (field names).');
});
}
catch(e) {
throw new Error('Error validating CSV file: ' + e.message);
}
return message; |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 13 replies
-
Can you post a sample valid CSV please? When your validation fails the first time, which error is thrown and what is the debugging output?
Are you sure its a question mark and not a non-printable character? Open the raw file in a text editor or hex editor and make sure. |
Beta Was this translation helpful? Give feedback.
-
Sorry, it took a while to reduce channel and CSV file... cannot share the original CSV because it contains PII data. Note: My question is not about finding another solution or workaround (see below, I can fix it myself). I'd like to understand why the 1st message processing fails while the 2nd (manual) attempt works fine while nothing has changed. Also I'd like to know where this strange question mark comes from (1st character in header row of inbound message, see 1st screenshot below). CSV file: Channel causing the error: Errors:
Same channel but slightly modified that succeeds: |
Beta Was this translation helpful? Give feedback.
-
Here is your sample CSV in a hex editor: You're seeing the I'm heading into morning meetings but I'll try to load your test channel and see how it can be fixed. I think the message works on the second try because either MC or the backing database are stripping out the non-ASCII characters on the reprocess attempt, but I am not sure. One of the first things to check is the file encoding in the file reader. There might be some workarounds or an explanation of the reprocessing behaviors on old forum threads . |
Beta Was this translation helpful? Give feedback.
-
This discussion was answered in the thread of messages, however no particular item was tagged as the exact answer by the orginal poster. |
Beta Was this translation helpful? Give feedback.
This discussion was answered in the thread of messages, however no particular item was tagged as the exact answer by the orginal poster.