web stats
"msg" is not defined when input is xml - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 06-01-2011, 06:45 AM
edwardw edwardw is offline
OBX.1 Kenobi
 
Join Date: Aug 2010
Posts: 43
edwardw is on a distinguished road
Default "msg" is not defined when input is xml

Hi

I have an xml message as input. I'd like to loop through repeating segments and store values in an SQL database:
msg['OPU_R25.SPECIMEN'][i]['SPM']['SPM.2']['EIP.1']['EI.1'].toString();

I receive this error message:
EcmaError: ReferenceError: "msg" is not defined

Is there some preformatting I must perform to access these segments?
Reply With Quote
  #2  
Old 06-01-2011, 08:55 AM
geraldb geraldb is offline
Mirth Employee
 
Join Date: Aug 2006
Location: Irvine, CA
Posts: 314
geraldb is an unknown quantity at this point
Default

Where are you using this script? In your transformer?
__________________
Gerald Bortis | Chief Information Officer | Mirth Corporation
Reply With Quote
  #3  
Old 06-01-2011, 11:24 AM
edwardw edwardw is offline
OBX.1 Kenobi
 
Join Date: Aug 2010
Posts: 43
edwardw is on a distinguished road
Default

No. In the database writer
Reply With Quote
  #4  
Old 06-01-2011, 01:50 PM
geraldb geraldb is offline
Mirth Employee
 
Join Date: Aug 2006
Location: Irvine, CA
Posts: 314
geraldb is an unknown quantity at this point
Default

In that case, you should create a mapping to that field in your transformer for that connector and use the mapping in the writer. You do not have access to the msg XML in that context, only the mapped variables and the message object.
__________________
Gerald Bortis | Chief Information Officer | Mirth Corporation
Reply With Quote
  #5  
Old 06-01-2011, 02:03 PM
edwardw edwardw is offline
OBX.1 Kenobi
 
Join Date: Aug 2010
Posts: 43
edwardw is on a distinguished road
Default

Is there a correct way to do this? I need to loop through multiple segments and save values to a database. I've checked documentation and the formum.
Thank you so much.
Reply With Quote
  #6  
Old 06-01-2011, 02:07 PM
geraldb geraldb is offline
Mirth Employee
 
Join Date: Aug 2006
Location: Irvine, CA
Posts: 314
geraldb is an unknown quantity at this point
Default

One way is to create a List object in your transformer and iterate through the segments adding each one. You can then iterate through the items in List in the Database Writer and execute the INSERT.
__________________
Gerald Bortis | Chief Information Officer | Mirth Corporation
Reply With Quote
  #7  
Old 06-02-2011, 06:41 AM
edwardw edwardw is offline
OBX.1 Kenobi
 
Join Date: Aug 2010
Posts: 43
edwardw is on a distinguished road
Default

Thanks so much. Should I do this in the Source or Destination transformer
Reply With Quote
  #8  
Old 06-02-2011, 10:50 AM
geraldb geraldb is offline
Mirth Employee
 
Join Date: Aug 2006
Location: Irvine, CA
Posts: 314
geraldb is an unknown quantity at this point
Default

You could do it in either, but if that list is only needed for that destination, I would do it that transformer.
__________________
Gerald Bortis | Chief Information Officer | Mirth Corporation
Reply With Quote
  #9  
Old 06-02-2011, 11:29 AM
edwardw edwardw is offline
OBX.1 Kenobi
 
Join Date: Aug 2010
Posts: 43
edwardw is on a distinguished road
Default

That sounds good. Would you be able to give me a skeleton of how the list could be set up?
Reply With Quote
  #10  
Old 06-02-2011, 01:59 PM
geraldb geraldb is offline
Mirth Employee
 
Join Date: Aug 2006
Location: Irvine, CA
Posts: 314
geraldb is an unknown quantity at this point
Default

Not the only way, but one way to do it:
Code:
importPackage(java.util);

var segments = new ArrayList();
segments.add("Foo");

for (var i = 0; i < segments.size(); i++) {
	logger.info(segments.get(i));
}
__________________
Gerald Bortis | Chief Information Officer | Mirth Corporation
Reply With Quote
Reply

Tags
iterate, loop, msg, xml

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 07:18 AM.


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