web stats
Alert Variables - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 01-07-2016, 11:42 AM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,310
cory_cole is on a distinguished road
Default Alert Variables

Is there a way to set a variable (a new variable) in the alert map from a channel?
Reply With Quote
  #2  
Old 01-07-2016, 12:41 PM
narupley's Avatar
narupley narupley is offline
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,124
narupley is on a distinguished road
Default

Well obviously you can always use the global map. However that's not ideal since you have to worry about map key collisions.

The alert template uses Velocity so technically you can do some rather complex things. For example say you sent an alert message that is really JSON:

Code:
var alert = {
	message: 'The message',
	customfield: 'Custom'
};
alerts.sendAlert(JSON.stringify(alert));
Then in your global deploy script you can create a custom parser to use in Velocity:

Code:
$g('jsonParser', new JavaAdapter(java.lang.Object, {
	get: function(json, name) {
		return JSON.parse(json)[name];
	}
}));
Then use it in your alert template:

Code:
#set($index=$error.indexOf('ERROR MESSAGE: ')+15)#set($json=$error.substring($index))Message: $jsonParser.get($json,'message')
Custom Field: $jsonParser.get($json,'customfield')
However it's a good idea to allow user-defined "alert map" variables from a channel JavaScript context, so I've added that as a feature request: MIRTH-3863
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #3  
Old 01-07-2016, 12:50 PM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,310
cory_cole is on a distinguished road
Default

What we are trying to do is have the sendto email as a variable as it will change based on certain conditions. We tried the GlobalMap put is was not available to use in the alert.
Reply With Quote
  #4  
Old 01-07-2016, 01:06 PM
narupley's Avatar
narupley narupley is offline
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,124
narupley is on a distinguished road
Default

Hm, just tried and it seemed to work fine for me.
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
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 05:26 PM.


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