web stats
SQL -> XML -> Delimited (CSV) - Page 2 - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #11  
Old 09-13-2018, 10:51 AM
yeruva yeruva is offline
Mirth Newb
 
Join Date: Nov 2017
Location: Dallas, USA
Posts: 24
yeruva is on a distinguished road
Default

I'm getting below error. Please find the attached channel for reference. could you please check and let me know what's issue

TypeError: setName is not a function, it is xml.
Attached Files
File Type: xml XML to CSV.xml (11.2 KB, 8 views)

Last edited by yeruva; 09-13-2018 at 11:10 AM.
Reply With Quote
  #12  
Old 09-13-2018, 11:24 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 747
agermano is on a distinguished road
Default

Your source connector is a Channel Reader, not a Database Reader. This thread was specifically for converting the XML returned by a Database Reader. If your XML messages are in a different format, please start a new thread.
Reply With Quote
  #13  
Old 01-22-2019, 01:13 PM
jbartels jbartels is offline
Mirth Guru
 
Join Date: Oct 2006
Posts: 719
jbartels is on a distinguished road
Default

I expanded Tonys code to also include a header row:

Code:
msg.setName('delimited'); // technically, this line is optional.
for each (var result in msg.result) result.setName('row');

//get the name of each element and add it as a header row
var headerRow = new XML('<row/>');
for each (var element in msg.row[0].children()){
	if (element != null){
		var name = element.name();
		var headerColumn = new XML('<' + name + '>' + name + '</' + name + '>');
		headerRow.appendChild(headerColumn);
	}
}
msg.prependChild(headerRow);
This looks clunky but it works.
__________________
Jon Bartels

Zen is hiring!!!!
http://consultzen.com/careers/
Talented healthcare IT professionals wanted. Engineers to sales to management.
Good benefits, great working environment, genuinely interesting work.
Reply With Quote
  #14  
Old 06-06-2019, 06:29 PM
sbwaxesson sbwaxesson is offline
What's HL7?
 
Join Date: Apr 2014
Posts: 1
sbwaxesson is on a distinguished road
Default

Quote:
Originally Posted by agermano View Post
All you need to do is convert the xml format returned by the database reader to the format expected by the delimited data type ...

Code:
msg.setName('delimited'); // technically, this line is optional.
for each (var result in msg.result) result.setName('row');
Whoa! This was incredibly useful to me. Thanks for posting it.

Tell me, how did you learn the details of the internal representations Mirth Connect uses for its various data types? I've been working with Connect for years, and the whole time I've been frustrated that I can't find clear and complete documentation of stuff like this. If you know of a resource I should be using, I'll be grateful to hear it!
Reply With Quote
  #15  
Old 06-07-2019, 09:40 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 747
agermano is on a distinguished road
Default

For the code you quoted, it was just looking at the transformed content of the two types and noticed they had a similar structure.

I do spend quite a bit of time poking around in the source code when I'm curious how certain things work. It's sparse on documentation, but the code base itself is pretty clean and easy to follow most of the time.

Today happens to be the 1-year annivesary of the announcement that they moved the public repo to github, which makes it more accessible than it was previously.

http://www.mirthproject.org/communit...d.php?t=218333

A local copy of the repo and a good IDE helps with browsing.
Reply With Quote
Reply

Tags
csv, delimited, sql, 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 12:06 AM.


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