Announcement

Collapse
No announcement yet.

Mirth - Flat file to Text channel

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mirth - Flat file to Text channel

    Hello All,

    I am trying to create a simple channel which will read a csv file and create a text message out for each row of file. I am using Mirth 3.5.1.
    I checked on this community and tried with some sample channels but facing an error as below,

    Either

    DETAILS: TypeError: Cannot read property "row" from undefined

    or

    DETAILS: TypeError: Cannot call method "elements" of undefined

    Attached my sample channel, Can anyone review the same and guide me what am I missing here.

    Thanks in advance.
    Attached Files

  • #2
    Originally posted by ahj610 View Post
    Hello All,
    <snip>
    DETAILS: TypeError: Cannot read property "row" from undefined

    or

    DETAILS: TypeError: Cannot call method "elements" of undefined
    </snip>.
    Your undefined message lead me to try assigning a value to msg and that seemed to work. But I struggled a little with the CSV syntax and came up with something that parses a CSV like this:

    ApptStatus,ApptDate,Name
    booked,01/01/2020,John Smith
    cancelled,02/19/2019,Jane Brown

    And outputs the following:

    Hello John Smith, your next appointment for 01/01/2020 is booked
    Hello Jane Brown, your next appointment for 02/19/2019 is cancelled

    I set up the source to read the file as a batch and ignore the header. and I didn't do much with the destination other than log the data. (got my day job to do! )

    Not sure if this is what you are looking for, but it may give you something that helps your needs. Attaching the channel, but it is in 3.7 so here's the destination side of things:

    Code:
    var msg = connectorMessage.getRawData();
    logger.info('msg is '+ msg);
    
    var arr = msg.split(",");
    
    
    //logger.info(arr[0])
    var status = (arr[0]);
    //logger.info(arr[1])
    var date = (arr[1]);
    //logger.info(arr[2])
    var name = (arr[2]);
    
    var note = 'Hello ' + name + ', your next appointment for '+ date + ' is ' + status;
    logger.info(note);
    Usual disclaimers - use at your own risk. Thank you to this forum and my co-workers for Mirth support. Hope this helps.
    Attached Files
    Last edited by Brad_AZ; 02-06-2019, 10:26 AM.
    SIG|1|Brad|Mirth Certified Interface Analyst^Cancer Treatment Centers of America

    Comment


    • #3
      Thanks Brad for your quick response.

      I am able to define the message however while trying to access row as below, its giving the same error.

      var msg = connectorMessage.getRawData();
      logger.info('msg is '+ msg); // This is working

      var appt_Status = msg['row'][0]['ApptStatus'].toString(); // This gives an error of
      DETAILS: TypeError: Cannot read property "0" from undefined.

      Even msg.elements('row').length() is also giving the same undefined error.

      As you mentioned, Splitting by (,) will not work here because the field might contain (,) in between a record e.g. "Dr John Doe, MD" as this is a single data.

      Thanks.

      Comment

      Working...
      X