Search code examples
javascriptxmlmirth

Mirth Connect Error: "...is not an xml object" when trying to output text from array


I have a strange issue. In the code below, I create a simple, one element array, x, as well as a simple variable, y. In the case of the array, I set the value of the first element to some text as I do with the variable. When I try to use logger.info to output the text, I get an error, which I do not get with the variable. I am using Mirth Connect 3.3.1.7856.

The code is below. Note that this is the ONLY code in the entire channel, all in a single source transformer step.

var x = [];

x[0] = 'abc';

var y = 'xyz';

logger.info('y: ' + y.toString());

logger.info('attachmentLength: ' + x.length);

logger.info.(x[0].toString());

The first two "logger.info" commands work just fine. Upon trying to execute the last one, however, the error below is logged.

SOURCE CODE:

170: var x = [];

171: x[0] = 'abc';

172: var y = 'xyz';

173: logger.info('y: ' + y.toString());

174: logger.info('attachmentLength: ' + x.length);

175: logger.info.(x[0].toString());

176: if ('xml' === typeof msg) {

177: if (msg.hasSimpleContent()) {

178: msg = msg.toXMLString();

179: }

LINE NUMBER:    175

DETAILS:    TypeError: function info() {/*

void info(java.lang.Object,java.lang.Throwable)

void info(java.lang.Object)

*/}

is not an xml object.

Notice lines 176-179 are not a part of my script. This is something Mirth is adding.

A few weeks ago, I had another issue in which a variable was being treated as a Java variable instead of a Javascript variable. The solution was to do something with the variable to make it a Javascript instead of a Java variable. Unfortunately, I can't remember enough about the issue or the solution to find it again or to even find in my code where I made the changes. Perhaps that is something I can try here.

Could it be the case that the array is being seen as a Java array instead of a Javascript array? If so, can I "force" it to be a Javascript array, somehow?

One other thing to note - all Data Types, including the source connector data types, are set to "Raw", meaning nothing should require any source data to be in any particular format, including XML.

I am at a complete loss as to how to troubleshoot this. Any assistance will be greatly appreciated.

Thanks,

MMall


Solution

  • Is it not your erroneous "." causing you the issue? Instead of:

    logger.info.(x[0].toString());
    

    You should have:

    logger.info(x[0].toString());