web stats
Mirth Community - View Single Post - Mirth Tools: User defined functions
View Single Post
  #55  
Old 04-24-2018, 10:54 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,026
agermano is on a distinguished road
Default Access globalChannelMap of any channel

Sometimes you need to alter the globalChannelMap of a running channel but do not want to stop it.

Code:
function $gcById(id, key, value) {
	var maps = com.mirth.connect.server.util.GlobalChannelVariableStoreFactory.getInstance();
	var map;
	if (maps.globalChannelVariableMap.containsKey(id)) {
		map = maps.get(id);
	}
	else {
		throw "globalChannelMap not found for channel: " + id;
	}

	if (arguments.length == 2) {
		return map.get(key);
	}
	else {
		return map.put(key, value);
	}
}
Usage is similar to $gc, except also pass the channelId of the channel for which you want to access or update the globalChannelMap.

Code:
$gcById('388f7dfc-4a1a-45a6-b89b-91faacd67044', 'test', 'added from another channel');
logger.info($gcById('febe3d1e-97d6-47eb-bfe0-ca6bf895c967', 'importantMap').toString());
Reply With Quote