web stats
Transform Javascript IF statement - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 02-15-2008, 07:54 AM
pfrey pfrey is offline
Mirth Newb
 
Join Date: May 2007
Posts: 15
pfrey
Default Transform Javascript IF statement

In my transformer I have a javascript step that is using a IF statement to populate the PV1.3.4 field in my HL7 message. I need the step to look at the PV1.2 field for a certain value and then populate the PV1.3.4 field based on that value. Below is the code that I am using.

if (msg['PV1']['PV1.2'].toString() == "E") {
msg['PV1']['PV1.3']['PV1.3.4'] = "WITHAM MEM ED";
} else {
msg['PV1']['PV1.3']['PV1.3.4'] = "WITHAM MEM";
}

When I send a message the transformed message tab shows the if statement working, but the encoded message does not have the PV1.3.4 field being populated. Any help would be appreciated.

Post edited by: pfrey, at: 02/15/2008 07:55
Reply With Quote
  #2  
Old 02-15-2008, 08:19 AM
afterdark23 afterdark23 is offline
OBX.2 Kenobi
 
Join Date: Oct 2007
Posts: 66
afterdark23
Default Re:Transform Javascript IF statement

Change the msg to tmp. I think the msg is the original message, and tmp is the message set to send to the outbound connection with all the transformers/modifications.


if (msg['PV1']['PV1.2'].toString() == "E") {

tmp['PV1']['PV1.3']['PV1.3.4'] = "WITHAM MEM ED";

} else {

tmp['PV1']['PV1.3']['PV1.3.4'] = "WITHAM MEM";

}
__________________
Reid Hospital and Healthcare
Reply With Quote
  #3  
Old 02-15-2008, 10:28 AM
pfrey pfrey is offline
Mirth Newb
 
Join Date: May 2007
Posts: 15
pfrey
Default Re:Transform Javascript IF statement

Thanks for the suggestion but it did not help. There is no message in the encoded tab and the transformed message is not displaying the change now either. I am using Mirth 1.6.1 if that makes a difference. Any other suggestions?
Reply With Quote
  #4  
Old 02-20-2008, 09:18 AM
pfrey pfrey is offline
Mirth Newb
 
Join Date: May 2007
Posts: 15
pfrey
Default Re:Transform Javascript IF statement

When I use tmp in the javascript code, it returns an error stating

ReferenceError: "tmp" is not defined.

When I change the code back to msg then the values do not appear in the PV1.3.4 field in the encoded message. Any other ideas or suggestions?

Thanks!
Reply With Quote
  #5  
Old 06-30-2014, 04:27 PM
brayton82 brayton82 is offline
What's HL7?
 
Join Date: Oct 2008
Posts: 2
brayton82
Default Temporary work space needed

AfterDark was correct, however, you need to declare the tmp variable before using it.


Code:
// Create a temporary workspace variable
tmp=msg;

if (msg['PV1']['PV1.2'].toString() == "E") {

tmp['PV1']['PV1.3']['PV1.3.4'] = "WITHAM MEM ED";

} else {

tmp['PV1']['PV1.3']['PV1.3.4'] = "WITHAM MEM";

}
Reply With Quote
  #6  
Old 07-02-2014, 09:29 AM
AlexToft AlexToft is offline
OBX.3 Kenobi
 
Join Date: Sep 2010
Location: Leeds, UK
Posts: 160
AlexToft is on a distinguished road
Default

tmp is only valid if you're using an outbound message template. If you're not using an outbound template you'll need to include 'return tmp;' at the end of your transformer or none of your modifications will work. I think... a little out of current practice.

The code originally posted looks sane. Try logger.info('Found E!'); inside the first braces so you can see the conditional match dumped to the console and verify that the logic is triggered by the condition.
Reply With Quote
Reply

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Invalid SQL statement svart Support 1 09-16-2008 05:31 AM
Conditional transform using Javascript bobneumann Support 3 02-20-2008 09:51 AM
Help with prepared statement in javascript josemathews Support 2 09-13-2007 01:24 AM
SQL statement processing coffde Support 3 01-03-2007 01:16 PM
Dinamic SQL Statement pitchfork Support 5 09-26-2006 04:10 PM


All times are GMT -7. The time now is 12:39 AM.


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