-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDBReadertoCSV.js
53 lines (44 loc) · 1.56 KB
/
DBReadertoCSV.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// 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);