Announcement

Collapse
No announcement yet.

Send alert when there are no errors

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

  • Send alert when there are no errors

    Hi,

    I'm trying to send alerts by email when I receive specific values on certain fields in the inbound message. There are no errors here.

    Most of the alert configuration variables for the message template are errorX errorY.

    For instance, how can I reference the message from the channel where I did the alerts.sendAlert() from the alert email template?

    Because errorMessage is not being populated.

    Thanks!


    Example template:

    Message ID: ${messageId}

    Alert:

    ${error}

    ${errorType}

    ${errorMessage}
    ----------------------


    Email body I receive:

    Message ID: ${messageId}


    Alert

    User Defined Transformer error
    ERROR MESSAGE: [object Object]

    User Defined Transformer

    No exception message.
    ----------------------

  • #2
    You have to pass a string to sendAlert, not an object. The string you send is what shows up in ${error}.

    The only template variable that isn't populating for you is ${messageId}, and I can't get that to work for me either, even when I tried:
    Code:
    new AlertSender(connectorMessage).sendAlert('TEST ALERT STRING');

    Comment


    • #3
      You are right, the messageId is the only not populated. What I tried to say is that I can't access the channel message from the alert email template.

      The object is the msg variable (that is a JSON object), I tried that because the message in the channel was not accessible (messageId not populated),

      I can to a JSON.stringify(msg) and pass that to alerts.sendAlert() to get the channel message in the ${error} variable, but this is not the cleanest way of doing it. Seems to be a little hacky. I'm surpriced alerts don't have a clear way of accessing the message from the channel at the moment the alert was triggered, that is a basic piece of info needed for debug in case of an error occurs, or like my case, just get the message by email under certain conditions.

      I know the email can be sent from JS directly, saw some code on stackoverflow I think. But it is a pity doing that by hand instead of being able to use the built in alerts.

      Thanks anyway for trying that out!

      Comment


      • #4
        I opened this issue: http://www.mirthcorp.com/community/i...wse/MIRTH-4245

        It's pretty clear to see in the source that it's not capturing the messageId from the connectorMessage or passing it to the new ErrorEvent. It would be the 3rd parameter, which is hard coded to null.
        http://www.mirthcorp.com/community/f...r.java?hb=true

        While it wouldn't be officially supported, you could replicate the functionality of AlertSender yourself and pass whatever you want to the new ErrorEvent. This worked for me. You could obviously wrap it up in a code template.

        Code:
        com.mirth.connect.server.controllers.ControllerFactory
        	.getFactory()
        	.createEventController()
        	.dispatchEvent(new com.mirth.connect.donkey.server.event.ErrorEvent(
        		connectorMessage.getChannelId(),
        		connectorMessage.getMetaDataId(),
        		connectorMessage.getMessageId(),
        		com.mirth.connect.donkey.model.event.ErrorEventType.USER_DEFINED_TRANSFORMER,
        		connectorMessage.getConnectorName(),
        		null, /* connectorType */
        		'A TEST ERROR MESSAGE',
        		null /* throwable */
        	)
        );
        Result (I added ${channelName} to the template to make sure it came through):
        Code:
        Error in channel: alert test
        
        Message ID: 3
        
        Alert:
        
        User Defined Transformer error
        ERROR MESSAGE: A TEST ERROR MESSAGE
        
        User Defined Transformer
        
        No exception message.

        Comment

        Working...
        X