web stats
Need Help Please: Read SQL Connections from Config File - Mirth Community

Go Back   Mirth Community > Mirth Connect > Development

Reply
 
Thread Tools Display Modes
  #1  
Old 12-19-2011, 11:00 AM
tfischer tfischer is offline
Mirth Newb
 
Join Date: Dec 2011
Posts: 17
tfischer is on a distinguished road
Default Need Help Please: Read SQL Connections from Config File

I've been looking on the forums for anything similar with no lick. This is what I need to do:

--create a code template to read from an XML config file
--Based on the passed connction name, find the connection value and return the string to be used with another code template that adds rows with HL7 data based on the connection string.

I originally tried with the ActiveXObject, however this appears to be for IE only.


Can anyone help me to determine how this is done in Mirth??

Here is the code:
================================================== =======
function GetServerConnectionString(connectionName, filePath)
{
//Get the connection file text
var connectionStringText = FileUtil.read(filePath);

var xmlDocument;
xmlDocument = new ActiveXObject("Microsoft.XMLDOM");
xmlDocument.loadXML(connectionStringText);


var connections = xmlDocument.GetElementsByTagName("ConnectionString ")[0];

if(connections)
{
var connectionNodes = connections.childNodes;

//Iterate through the entries
for(var i = 0; i < connectionNodes.Length; i++)
{
var sqlConnectionName = connections[i].getAttribute("name");
var sqlConnectionString = connections[i].getAttribute("value");

var fullString = sqlConnectionName + " --> " + sqlConnectionString + "\r\n";
FileUtil.write("C:\TEMP\ERR\Conns.txt", fullString);
}
}
}
Reply With Quote
  #2  
Old 12-19-2011, 03:54 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

If you doing this in a deploy or transformer script, you should be using E4X as your tool for parsing and working with XML in JavaScript. You can find many examples here on the forum for how to create a new XML object from the contents of a file and iterate through the elements.

Here is a good E4X guide:

http://web.archive.org/web/200807031...phtml/fid/1762
__________________
Gerald Bortis | Chief Information Officer | Mirth Corporation
Reply With Quote
Reply

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:12 PM.


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