Mirth Community

Mirth Community (http://www.mirthcorp.com/community/forums/index.php)
-   Support (http://www.mirthcorp.com/community/forums/forumdisplay.php?f=6)
-   -   Conditionally Edit CSV Help (http://www.mirthcorp.com/community/forums/showthread.php?t=14790)

mshort 06-17-2015 09:56 PM

Conditionally Edit CSV Help
 
1 Attachment(s)
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!

flyerman 06-17-2015 11:20 PM

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

flyerman 06-17-2015 11:40 PM

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>

mshort 06-18-2015 07:17 AM

Quote:

Originally Posted by flyerman (Post 49112)
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>

:DThis was the issue! Didn't realize I still had that in there, removed the Outbound Message Template, and it does work fine!:D

Thank You flyerman!!!

Quote:

Originally Posted by flyerman (Post 49110)
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.

flyerman 06-18-2015 08:06 AM

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.

mshort 06-18-2015 11:18 AM

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!


All times are GMT -8. The time now is 03:20 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation