web stats
Mirth Community - View Single Post - SQL -> XML -> Delimited (CSV)
View Single Post
  #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