web stats
Conditionally Edit CSV Help - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 06-17-2015, 09:56 PM
mshort mshort is offline
Mirth Newb
 
Join Date: Apr 2015
Posts: 7
mshort is on a distinguished road
Default 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
File Type: xml CSV_Manipulator.xml (17.1 KB, 9 views)
Reply With Quote
  #2  
Old 06-17-2015, 11:20 PM
flyerman flyerman is offline
OBX.2 Kenobi
 
Join Date: May 2015
Posts: 68
flyerman is on a distinguished road
Default

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 at 11:30 PM.
Reply With Quote
  #3  
Old 06-17-2015, 11:40 PM
flyerman flyerman is offline
OBX.2 Kenobi
 
Join Date: May 2015
Posts: 68
flyerman is on a distinguished road
Default

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>
Reply With Quote
  #4  
Old 06-18-2015, 07:17 AM
mshort mshort is offline
Mirth Newb
 
Join Date: Apr 2015
Posts: 7
mshort is on a distinguished road
Default

Quote:
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!!!

Quote:
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.
Reply With Quote
  #5  
Old 06-18-2015, 08:06 AM
flyerman flyerman is offline
OBX.2 Kenobi
 
Join Date: May 2015
Posts: 68
flyerman is on a distinguished road
Default

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 at 08:22 AM.
Reply With Quote
  #6  
Old 06-18-2015, 11:18 AM
mshort mshort is offline
Mirth Newb
 
Join Date: Apr 2015
Posts: 7
mshort is on a distinguished road
Default

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!
Reply With Quote
Reply

Tags
conditionally, csv, edit, iterate, text file

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 05:08 PM.


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