web stats
Send alert when there are no errors - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 02-19-2018, 10:34 AM
ppazos ppazos is offline
OBX.2 Kenobi
 
Join Date: May 2008
Posts: 76
ppazos
Default 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.
----------------------
Reply With Quote
  #2  
Old 02-19-2018, 01:00 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 894
agermano is on a distinguished road
Default

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');
Reply With Quote
  #3  
Old 02-20-2018, 07:43 PM
ppazos ppazos is offline
OBX.2 Kenobi
 
Join Date: May 2008
Posts: 76
ppazos
Default

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!
Reply With Quote
  #4  
Old 02-21-2018, 05:26 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 894
agermano is on a distinguished road
Default

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.
Reply With Quote
Reply

Tags
alerts

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


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