Created
April 7, 2018 05:38
-
-
Save bluengreen/e9b254f3231020c98b219aa5e384859c to your computer and use it in GitHub Desktop.
Mirth CSV file to collection of JavaScript literals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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