-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Notes: Assumes you have aggregate results set to yes on the DB reader | ||
// Do not use an outbound template with this solution. | ||
// Code courtesy of Tony Germano and Jon Bartels, original forum thread: https://forums.mirthproject.io/forum/mirth-connect/support/16869- | ||
|
||
|
||
// Set the root element name to 'delimited' (optional but mentioned) | ||
msg.setName('delimited'); | ||
|
||
// Loop through each result in the 'msg.result' collection and rename them to 'row' | ||
for each (var result in msg.result) { | ||
result.setName('row'); | ||
} | ||
|
||
// Create a header row for the XML data | ||
var headerRow = new XML('<row/>'); | ||
|
||
// Iterate through each element in the first 'msg.row' (assuming it exists) and create header columns | ||
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); | ||
} | ||
} | ||
|
||
// Prepend the header row to the XML message | ||
msg.prependChild(headerRow); |