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

Conditional execution of channel

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

  • Conditional execution of channel

    Hi,

    I've made a channel with Database reader in source and File Writer in destination with 10 minutes of polling frequency.

    I want this channel running only between 10:00 and 12:00 so I've wrote some javascript in the source area like this:

    Code:
    var vSQL = " select  rownum as nomfit, ";
    vSQL = vSQL + "        visi_centre_codi_centre as centre, ";
    vSQL = vSQL + "...";
    
    var result=""
    var Hora=DateUtil.getCurrentDate('HH');
    
    if (Hora>="10" && Hora <="12"«»)
    	{ 
    	var dbConn = DatabaseConnectionFactory.createDatabaseConnection('oracle.jdbc.OracleDriver','jdbc:oracle:thin:@10.80.217.40:1521:orac','RADHTR','xxxxxx');
    	result = dbConn.executeCachedQuery(vSQL);
    	dbConn.close();
    	}
    
    // YOUR CODE GOES HERE 
    
    // You may access this result with $('column_name')
    return result;
    this code runs correctly but I've got the following message when the channel works before 10:00 and after 12:00 because result variable hasn't a proper value.
    "[2008-09-23 06:26:53,938] ERROR (com.webreach.mirth.connectors.jdbc.JdbcMessageRec eiver:240): Got a result of:"

    Somebody could help me?

    thanks

    carles massallé

  • #2
    Re:Conditional execution of channel

    First of all, I know that the following is a dirty hack:

    If the problem is that Mirth is complaining about the type of the resultset, you can do something like (pseudocode):
    Code:
    if (hour between 10 and 12) {
    strQuery = "select asdfasdf from table1"
    }
    else {
    strQuery = "select * from table1 where 1=0" 
    }
    
    dbConn = DatabaseConnectionFactory.createDatabaseConnection('oracle.jdbc.OracleDriver','jdbc:oracle:thin:@10.80.217.40:1521:orac','RADHTR','xxxxxx');
        result = dbConn.executeCachedQuery(strQuery);
        dbConn.close();
    
    return result;
    Or better, you can try a select that returns an empty resultset and see how a empty resultset is formed. Perhaps is a XML like:

    Code:
    <result>
    <field1>VALUE1</field1>
    <field2>VALUE2</field2>
    </result>
    If so, you can forge an empty resultset and avoid executing a tricky query.

    PD: Salut desde Barcelona!

    Post edited by: quimicefa, at: 09/23/2008 04:27

    Comment


    • #3
      Re:Conditional execution of channel

      If I did that I'd ask to database every time the channel worked and this is just what I pretend to avoid.

      The source database is a production one and I must minimize every unnecessary access.

      But, forge an empty resultset by hand could be a good solution.

      I'll try it

      thanks quimicefa



      PD: Salutacions des de Girona

      carles massallé

      Post edited by: carles, at: 09/23/2008 05:41

      Post edited by: carles, at: 09/23/2008 05:42

      Comment


      • #4
        Re:Conditional execution of channel

        hi again,

        I've tried to forge an empty resultset by hand and it doesn't works.
        Shame.

        I'm not sure how to put a custom value into result variable, actually.

        I did this:

        Code:
        result="<result><field1>1</field1></result>"
        and I've got the following error message:

        Got a result of: <result><field1>1</field1></result>

        Comment


        • #5
          Re:Conditional execution of channel

          About the manual forging of the resultset, try this:

          result=new XML("<result><field1>1</field1></result>");

          but you should ensure that the XML structure matches the expected one

          See you!

          Comment


          • #6
            Re:Conditional execution of channel

            Thanks Quimicefa.

            I've tried this and works fine.

            I didn't know how to put XML in a variable.

            I've found another simple solution to my issue that is:

            Code:
            return false;
            when I don't want to query database.


            carles

            Comment

            Working...
            X