Skip to content

Instantly share code, notes, and snippets.

@bluengreen
Created April 7, 2018 05:38
Show Gist options
  • Save bluengreen/e9b254f3231020c98b219aa5e384859c to your computer and use it in GitHub Desktop.
Save bluengreen/e9b254f3231020c98b219aa5e384859c to your computer and use it in GitHub Desktop.
Mirth CSV file to collection of JavaScript literals
//the Mirth file reader has a CSV file (now in the msg object)
//be sure your channel's incoming data type is 'delimited text'
//let's pretend this csv contains customers
var customers = [];
var header = msg.row[0];
for(var i=1;i<msg['row'].length();i++)
{
var cust = {};
for (col in msg.row[i].children()) {
var columnName = header.children()[col];
//set the customer property, by name, based on the name of the column in the header row
cust[columnName] = msg['row'][i].children()[col].toString();
}
customers.push(cust);
}
//you now have an array of customer objects.
channelMap.put("customers", customers);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment