No announcement yet.

Ability to write to the configuration map

  • Filter
  • Time
  • Show
Clear All
new posts

  • Ability to write to the configuration map

    wondering if NextGen Connect had plans to allow the configuration map values to be updated in code (within Mirth) as a place to store a static value, and read and update that value as the state changes??

    something like:
    configurationMap.put("key", value) and/or configurationMap.update("key", value)

  • #2
    The globalMap already does this, but I think your intention is to also persist the data.

    While I can't speak for them, I don't think they have any plans to do that. They explicitly make the Map immutable before handing it off to user code. Part of the reason for this is that there is a comment associated with each key as well as a value.

    Here's a code template that will do what you want, but before using it consider:
    1. This method is unsupported and could break without notice during future updates. You could make it more future proof by using the Client API, but then you need to deal with providing valid login credentials.
    2. The configuration map is read and written as a whole. This copies the entire map, makes your change, and commits the entire map back to the db. You could end up with lost changes if multiple threads try doing this at the same time and you don't implement any additional locking mechanism to ensure only one thread is updating the map at a time.

    function updateConfigurationMap(key, value, comment) {
    	const ControllerFactory = com.mirth.connect.server.controllers.ControllerFactory;
    	const ConfigurationProperty = com.mirth.connect.util.ConfigurationProperty;
    	if (comment == null) comment = '';
    	const configurationController = ControllerFactory.getFactory().createConfigurationController();
    	const props = configurationController.getConfigurationProperties();
    	var result = props.put(key, new ConfigurationProperty(value, comment));
    	if (result != null) {
    		result = result.getValue();
    	configurationController.setConfigurationProperties(props, true);
    	return result;
    I think you'd be better off using a database to persist the information. You can either write a code template or a dedicated channel that can be called by your other channels to read and write values. If you don't want to stand up a new database server or piggyback on the existing mirthdb, mirth also ships with a sqlite driver which can be backed by a local file and should avoid the mentioned concurrency issues.

    As I mentioned in my post to your other thread, you could also try using the saveProperty and getProperty methods on the ConfigurationController.