Announcement

Collapse
No announcement yet.

Conditionally Edit CSV Help

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

  • Conditionally Edit CSV Help

    Hello,

    I'm using Mirth Connect 3.2.1.7650. [Mirth amateur here, so go easy on me]

    I'm wanting to conditionally edit specific values in a csv. I've used a similar transformer logic to conditionally edit repeating HL7 fields and it worked fine. This is my first time working with csv files and looking to do the same. The csv looks like:
    last_name,first_name,dob
    mouse,mickey,4/25/1946
    duck,donald,7/7/1977
    doo,scooby,1/1/1901

    My destination transformer simply looks like:
    for(var i = 0; i< msg['row'].length(); i++) {
    if (msg['row'][i]['column1'].toString() == "mouse") {

    msg['row'][i]['column1']= "test";
    }
    }

    I'm attempting to set the last_name = "test" if the last_name = "mouse", however I can't seem to get this update/replace/set to actually happen.

    [I've attached my channel if it helps]

    Any help is greatly appreciated!
    Attached Files

  • #2
    I tested your code on Mirth 3.1.1.7461

    Your code is working fine

    mouse --> test


    _______________
    Can U put a few logger.info to confirm everything is correct

    logger.info("msg['row'][1]['column1'].toString() before loop = " + msg['row'][1]['column1'].toString())
    for(var i = 0; i< msg['row'].length(); i++) {
    logger.info("i = " +i)
    if (msg['row'][i]['column1'].toString() == "mouse") {

    msg['row'][i]['column1']= "test";
    }
    }

    logger.
    info("msg['row'][1]['column1'].toString() after loop= " + msg['row'][1]['column1'].toString())

    The log should comes out as
    INFO (transformer:?): msg['row'][1]['column1'].toString() before loop = mouse
    INFO (transformer:?): i = 0
    INFO (transformer:?): i = 1
    INFO (transformer:?): i = 2
    INFO (transformer:?): i = 3
    INFO (transformer:?): msg['row'][1]['column1'].toString() after loop= test
    Last edited by flyerman; 06-17-2015, 10:30 PM.

    Comment


    • #3
      I see

      You have mistakenly put your testing message in the outbound template

      Remove it!
      You are hard coding your outbound message

      ______________
      <inboundTemplate encoding="base64">bGFzdF9uYW1lLGZpcnN0X25hbWUsZG9i DQptb3VzZSxtaWNrZXksNC8yNS8xOTQ2DQpkdWNrLGRv bmFsZCw3LzcvMTk3Nw0KZG9vLHNjb29ieSwxLzEvMTkwMQ0K</inboundTemplate>

      <outboundTemplate encoding="base64">bGFzdF9uYW1lLGZpcnN0X25hbWUsZG9iDQptb3VzZSxtaWNrZX ksNC8yNS8xOTQ2DQpkdWNrLGRv bmFsZCw3LzcvMTk3Nw0KZG9vLHNjb29ieSwxLzEvMTkwMQ0K</outboundTemplate>

      Comment


      • #4
        Originally posted by flyerman View Post
        I see

        You have mistakenly put your testing message in the outbound template

        Remove it!
        You are hard coding your outbound message

        ______________
        <inboundTemplate encoding="base64">bGFzdF9uYW1lLGZpcnN0X25hbWUsZG9i DQptb3VzZSxtaWNrZXksNC8yNS8xOTQ2DQpkdWNrLGRv bmFsZCw3LzcvMTk3Nw0KZG9vLHNjb29ieSwxLzEvMTkwMQ0K</inboundTemplate>

        <outboundTemplate encoding="base64">bGFzdF9uYW1lLGZpcnN0X25hbWUsZG9iDQptb3VzZSxtaWNrZX ksNC8yNS8xOTQ2DQpkdWNrLGRv bmFsZCw3LzcvMTk3Nw0KZG9vLHNjb29ieSwxLzEvMTkwMQ0K</outboundTemplate>
        This was the issue! Didn't realize I still had that in there, removed the Outbound Message Template, and it does work fine!

        Thank You flyerman!!!

        Originally posted by flyerman View Post
        I tested your code on Mirth 3.1.1.7461

        Your code is working fine

        mouse --> test


        _______________
        Can U put a few logger.info to confirm everything is correct

        logger.info("msg['row'][1]['column1'].toString() before loop = " + msg['row'][1]['column1'].toString())
        for(var i = 0; i< msg['row'].length(); i++) {
        logger.info("i = " +i)
        if (msg['row'][i]['column1'].toString() == "mouse") {

        msg['row'][i]['column1']= "test";
        }
        }

        logger.
        info("msg['row'][1]['column1'].toString() after loop= " + msg['row'][1]['column1'].toString())

        The log should comes out as
        INFO (transformer:?): msg['row'][1]['column1'].toString() before loop = mouse
        INFO (transformer:?): i = 0
        INFO (transformer:?): i = 1
        INFO (transformer:?): i = 2
        INFO (transformer:?): i = 3
        INFO (transformer:?): msg['row'][1]['column1'].toString() after loop= test
        I added the logger info above and it recorded something slightly different that what you expected (even though as mentioned above, the code does work now that I removed the outbound message template). Here is what my log came out as:
        INFO (transformer:?): msg['row'][1]['column1'].toString() before loop = test
        INFO (transformer:?): i = 0
        INFO (transformer:?): i = 1
        INFO (transformer:?): i = 2
        INFO (transformer:?): i = 3
        INFO (transformer:?): msg['row'][1]['column1'].toString() after loop= test[/QUOTE]

        So I'm not exactly sure what's going, but your expected before/after loop made since to me and I expected exactly that to be logged...I don't understand why it's logging "test" before the loop and after. But the code works none the less.

        Comment


        • #5
          are you are reading the log upside down?

          your log should look like:
          test
          3
          2
          1
          0
          mouse

          the initial log is placed below the final log, as the log in Dashboard is in reverse chronological order.
          look at the time stamp at left side of each log, you will see "mouse" is few milliseconds before "0"

          i write the previous post in Chronological order for readability.


          you can learn a lot by logging when debuking the code. i usually commented the log at production to reduce unnecessary step.
          Last edited by flyerman; 06-18-2015, 07:22 AM.

          Comment


          • #6
            It's logging correctly and as you expected. I added the logging step with loop after my original step with the loop and no logging. So the data had already been changed before the logging took place.

            Works perfect after I removed my original (now duplicated loop step).

            Thanks again!

            Comment

            Working...
            X