Announcement

Collapse
No announcement yet.

Update database based on TCP Sender Status

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

  • Update database based on TCP Sender Status

    Hello,

    I have a channel with a database reader source and multiple destinations, the main one being a TCP sender (the other destinations are just SMTP senders for notifications). On the source side I also have a JavaScript filter to do some validation of the source data and set a variable that gets updated as part of the database reader post processing SQL.

    For example, here is the update run in the post process script for the database reader:

    Code:
    var result = dbConn.executeUpdate("UPDATE electronicreports SET 
    releaseProcessed = " + $c('idx_releaseProcessed') + ", releaseDate = NOW()
     WHERE oid = " + $('oid'));
    The variable $c('idx_releaseProcessed') is set in the source JavaScript filter based on our source data. This all works as expected.

    Now, what I am looking to do is add another column to that update query based on the status of the TCP Sender destination. For example:

    Code:
    var tcpSenderStatus = 0;
    if ("the tcpSender was successful") {
        tcpSenderStatus = 1;
    }
    
    var result = dbConn.executeUpdate("UPDATE electronicreports SET
     releaseProcessed = " + $c('idx_releaseProcessed') + ", releaseDate = 
    NOW(), tcpSenderStatus = " + tcpSenderStatus + " WHERE oid = " + 
    $('oid'));
    I've reviewed the documentation and done some searches for a similar request but didn't find what I was looking for.

    Any help would be greatly appreciated!

  • #2
    I ended up answering my own question by piecing together several other posts in the forums. Figured I'd post the details here in case it can benefit anyone else.

    Instead of doing this specific update as part of the source post processing SQL, I kept that simply updating the record to "processed" so it doesn't get picked up again. Then I added a Database Writer destination next in order after the TCP Sender to use for any types of updates that may be needed now or in the future. The idea came from this post: http://www.mirthproject.org/communit...ad.php?t=15203

    I then used this Javascript snippet in the Database Writer destination to check the status of the previous destination (TCP Sender) and set the flag I wanted accordingly using the getStatus function.

    Code:
    // Use this destination to do any updates to the database based on the status of sending the message.  
    // The source post processing should be kept to just updating the record so it does not get processed again.
    
    // Set the tcpSenderStatus based on whether or not the TCP message was sent
    var tcpSenderStatus = 0;
    if($('d5').getStatus() == 'SENT') {
    	tcpSenderStatus = 1;
    }
    	
    var dbConn;
    try {
    	dbConn = DatabaseConnectionFactory.createDatabaseConnection();
    	var result = dbConn.executeUpdate("UPDATE table SET tcpSenderStatus = " + tcpSenderStatus + " WHERE oid = " + $('oid'));
    } finally {
    	if (dbConn) { 
    		dbConn.close();
    	}
    }
    It took me a while to find how to access the previous destination like this (eg, the $('d5')). Turns out they are listed in the Destination Mappings box by name and can be dragged over to your script which translates to their ID.

    Comment

    Working...
    X