web stats
Send Alert Variables To A Channel - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 02-20-2019, 12:19 PM
kirbyjwilson kirbyjwilson is offline
OBX.2 Kenobi
 
Join Date: May 2012
Posts: 61
kirbyjwilson is on a distinguished road
Default Send Alert Variables To A Channel

I want to create a reusable "Alert Receiver" channel that receives alert variables and writes them to a table.

I have an alert; rather than send an email (Actions -> Protocol -> Email), I have it configured to run the "Alert Receiver" channel (Actions -> Protocol -> Channel). Will all of the alert variables (e.g. alertId, error, channelName) be available to the channel?
Reply With Quote
  #2  
Old 02-20-2019, 06:05 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,028
agermano is on a distinguished road
Default

They will not be available in the destination channel. However, your alert template will be passed as the message, so you can add them all to the template.
Reply With Quote
  #3  
Old 03-04-2019, 11:35 AM
kirbyjwilson kirbyjwilson is offline
OBX.2 Kenobi
 
Join Date: May 2012
Posts: 61
kirbyjwilson is on a distinguished road
Default

So it sounds like I won't be able to write the name/value pairs (i.e. the values of the alert variables) to a database? They'll only be available via an email?
Attached Images
File Type: jpg Mirth Alert.jpg (23.5 KB, 6 views)
Reply With Quote
  #4  
Old 03-04-2019, 12:20 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,028
agermano is on a distinguished road
Default

What you have in the template will be passed as the message to the channel in the same way it would appear in an email body. You can parse the message to get all of the name/value pairs.
Reply With Quote
  #5  
Old 03-04-2019, 12:42 PM
kirbyjwilson kirbyjwilson is offline
OBX.2 Kenobi
 
Join Date: May 2012
Posts: 61
kirbyjwilson is on a distinguished road
Default

Ah, so instead of setting the Action Protocol to Email I should set it to Channel (refer to the attached screen shot) and then those variables will be available in the destination channel (in this case, the "Alert Receiver" channel)?
Attached Images
File Type: jpg Alert Receiver.jpg (20.5 KB, 6 views)
Reply With Quote
  #6  
Old 03-04-2019, 12:51 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,028
agermano is on a distinguished road
Default

What you have in the template of your screenshot will be in msg in your transformer. You'll have to pull the values back out from there.

You can try formatting your template as JSON or xml to make it easier to get the values by setting the appropriate data type in your channel. The way you have it now, you'll probably have to set your inbound type to Raw.
Reply With Quote
  #7  
Old 03-04-2019, 02:05 PM
kirbyjwilson kirbyjwilson is offline
OBX.2 Kenobi
 
Join Date: May 2012
Posts: 61
kirbyjwilson is on a distinguished road
Default

I appreciate your help on this.

I modified the alert to only pass one variable (errorMessage) to the Alert Receiver channel (for testing purposes). I attached that screen shot.

Also attached is the Alert Receiver channel. Data types are set to Raw. I created a Source Transformer:

Type: Mapper
Variable: errorMessage
Mapping: msg['errorMessage'].toString()

The Destination contains a simple script that will (hopefully) write the value or errorMessage to a table.

I don't have a Destination transformer.

The error I'm getting (which has to do with the Source Transformer) is:

Cannot call method "toString" of undefined
Attached Images
File Type: jpg Simple Alert.jpg (13.4 KB, 5 views)
Attached Files
File Type: xml Alert Receiver.xml (8.7 KB, 2 views)
Reply With Quote
  #8  
Old 03-04-2019, 05:15 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,028
agermano is on a distinguished road
Default

In this case, msg is your errorMessage. Look at the raw content of your message.

Probably what I would do so that you don't have to worry about escaping is use the delimited data type, and pick some really weird delimiters that are unlikely to ever come up in your real data.

For example,
Code:
Column Delimiter = |&|
Record Delimiter = @#@
Quote Token = $$%
Column Names = alertId,alertName,errorMessage,errorType
Then in your alert template,
Code:
${alertId}|&|${alertName}|&|${errorMessage}|&|${errorType}
Add as many as you want and make sure the column names in the delimited data type property match. Then you can either map them one at a time like you were trying to do, or you should be able to create all of your channelMap variables at once in a javascript step like this,

Code:
for each (var col in msg.row.children()) {
    $c(col.name().toString(), col.toString());
}
Reply With Quote
  #9  
Old 03-05-2019, 08:58 AM
kirbyjwilson kirbyjwilson is offline
OBX.2 Kenobi
 
Join Date: May 2012
Posts: 61
kirbyjwilson is on a distinguished road
Default

This is the new error that is being generated:

5be48cdf-6f87-4527-9b24-7adf39a23c82|&|Call Alert Receiver|&|
CHANNEL: Alert Receiver
CONNECTOR: sourceConnector
SCRIPT SOURCE: TRANSFORMER
SOURCE CODE:
504: function doScript() {
505: if (connectorMessage.getProcessedRawData() != null) { msg = new String(connectorMessage.getProcessedRawData()); } else { msg = new String(connectorMessage.getRawData()); }
506: function doFilter() { phase[0] = 'filter'; return true; }function doTransform() { phase[0] = 'transformer'; logger = Packages.org.apache.log4j.Logger.getLogger(phase[0]);
507:
508:
509: for each (var col in msg.row.children()) {
510: $c(col.name().toString(), col.toString());
511: }
512: if ('xml' === typeof msg) {
513: if (msg.hasSimpleContent()) {
LINE NUMBER: 509
DETAILS: TypeError: Cannot call method "children" of undefined
at 3bb5b51e-81ae-49b5-85ca-a40970ad0ab3:509 (doTransform)
at 3bb5b51e-81ae-49b5-85ca-a40970ad0ab3:533 (doScript)
at 3bb5b51e-81ae-49b5-85ca-a40970ad0ab3:535|&|Transformer
Reply With Quote
  #10  
Old 03-05-2019, 09:06 AM
kirbyjwilson kirbyjwilson is offline
OBX.2 Kenobi
 
Join Date: May 2012
Posts: 61
kirbyjwilson is on a distinguished road
Default

Attached are the latest files.
Attached Files
File Type: xml Call Alert Receiver.xml (1.7 KB, 1 views)
File Type: xml Alert Receiver.xml (8.7 KB, 2 views)
Reply With Quote
Reply

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 08:01 AM.


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