Announcement

Collapse

Mirth Connect 3.12.0 Released!

Mirth Connect 3.12.0 is now available as an appliance update and on our GitHub page. This release includes database performance improvements, improves visual HL7 representation, message pruning, keystore handling, PDF generation, community contributions, and fixes several security vulnerabilities. This release also contains many improvements to commercial extensions. See the release notes for the list of fixes and updates.

Download | See What's New | Upgrade Guide | Release Notes

For discussion on this release, see this thread.
See more
See less

Interesting JavaScript Behavior

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Interesting JavaScript Behavior

    Something I noticed within Mirth 1.7.1 JavaScript for the Database Writer...

    If I do a very basic JavaScript execution, the SQL works fine:
    var sqlstatement = "UPDATE DATATABLE SET newDATA = 'help' WHERE newID = 28821";
    var result = dbConn.executeUpdate(sqlstatement);

    If I add a variable to the JavaScript statement, the SQL does not work:
    var helpVar = 'helpme';
    var sqlstatement = "UPDATE DB2.DATATABLE SET newDATA = " + helpVar + " WHERE newID = 28821";
    var result = dbConn.executeUpdate(sqlstatement);

    If I add a Mirth Unique ID variable to the JavaScript statement, the SQL does not work:
    var uniqueID = $('uuid');
    var sqlstatement = "UPDATE DB2.DATATABLE SET newDATA = '" + uniqueID + "' WHERE newID = 28821";
    var result = dbConn.executeUpdate(sqlstatement);

    I don't know if this is a syntax problem. I thought the '+' operator is the proper concatenation syntax but it does something to mess up the JavaScript. If anyones gotten the custom Javascript to function in Mirth, could you provide me an example of the syntax used with the variable call to get your JavaScript to execute succesfully?

    Thanks for any insight on this problem!

    Post edited by: nictac, at: 05/07/2008 20:23

  • #2
    Re:Interesting JavaScript Behavior

    I had a similar problem. It had to due with how I 'quoted' my string.

    Here is my string to perform a query with a variable:
    Code:
    var result = dbConn.executeCachedQuery("select * from VIPAlert where Alerts Like '%" + alertType + "%';"«»);
    Your newData column appears to take a string, which will need to be quoted. I will use Double Quotes ["] to build my string, then Single Quotes ['] to quote withing my string.

    So that would make your queries read like this:
    Code:
    var sqlstatement = "UPDATE DB2.DATATABLE SET newDATA = '" + helpVar + "' WHERE newID = 28821";
    Post edited by: wseay, at: 05/08/2008 18:39

    Comment

    Working...
    X