Search code examples
mirth

How to parse a string into a list in Mirth Connect?


I use Mirth Connect version 3.7,

I need to parse a global variable globalVariable defined in global settings and use it's value in one of destination filters.

This variable contains comma-separated values.

globalVariable= 'A,B,C'

I use that variable in a Javascript code inside a destination filter.

var someValue = 'B';
var arr = $('globalVariable');
if (arr && arr.split(',').includes(someValue)) {
  return  true;
}
return false;

But somehow Mirth-Connect cannot transform my code correctly. It complaints about that type not having include() method. What am I doing wrong here? I expected after split() to have a Javascript array.


Solution

  • Mozilla Rhino is the javascript engine that Mirth uses. It doesn't have Array.prototype.includes.

    You can do this instead:

    if (arr && arr.split(',').indexOf(someValue) > -1) {
      return  true;
    }
    return false;
    

    Here's the Rhino javascript feature compatibility chart. To have access to the latest features you need to be running mirth 3.7+ in "ES6" mode. https://mozilla.github.io/rhino/compat/engines.html