Link to home
Start Free TrialLog in
Avatar of Jeff Darling
Jeff DarlingFlag for United States of America

asked on

Mirth Connect Read File - Javascript

I'm looking for a sample script using Mirth Connect to read a ASCII Text.  The text file is formatted like a proprietary transaction file.  Each line is a delimited record, but there are multiple record types within the file,  just like a transaction file would have.

Example

GG1,John,Smith
GG2,"207 Main Street",Springfield,MA,02134
GG3,ITM001,"Red Pencil Sharpener"
GG3,ITM005,"Shoe Laces"
GG3,ITM014,"Bicycle pump"
GG4,400.02
GG5,"Repeat Customer Award",102.44

Open in new window


I need the records to go into 3 different MSSQL database tables

GG1 and GG2 records go into the customer table.
GG3  records go into the items table.
GG4 and GG5  records go into the benefits table.

Since noone is answering this question,   I have decided to simplify the question, and also add more detail.

I need help getting the Javascript and more specifically, how to use Javascript within the mirth application as part of the channel setup.

For the sake of simplicity, lets just say only the GG1 and GG2 lines to extract the info (using Mirth)

GG1,John,Smith
GG2,"207 Main Street",Springfield,MA,02134

Open in new window


more details

I have made some progress and have a code snippet that works, but definitely depends on good clean data.

var msg = connectorMessage.getRawData()

//Convert from Java string to Javascript 
var msgTemp = String(new java.lang.String(msg));

// verify msg is populated with the message
logger.info('msg='+msg);
logger.info('msgTemp='+msgTemp);

// get rid of crlf
msg = msgTemp.replace(/[\n\r]+/g, ',');

// verify msg is populated with the message
logger.info('msg='+msg);

// split the string into res array
var res = msg.split(",");

// Sample String
// GG1,John,Smith

// firstname element should be populated with John
tmp['firstname'] = res[1];
// lastname element should be populated with Smith
tmp['lastname'] = res[2];

Open in new window


This code is under the source Transformer Step.

User generated image
at this point, my question needs to be revised to - Is there a better way to do this using the Mirth Connect Tool?
ASKER CERTIFIED SOLUTION
Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial