com.mirth.connect.server.MirthJavascriptTransformerException: SOURCE CODE: 1: String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,"").replace(/^\t+|\t+$/g,""); };function $(string) { if (globalChannelMap.containsKey(string)) { return globalChannelMap.get(string);} else if (globalMap.containsKey(string)) { return globalMap.get(string);} else { return ''; }}function addAttachment(data, type) {var attachment = Packages.com.mirth.connect.server.controllers.MessageObjectController.getInstance().createAttachment(data, type);muleContext.getProperties().get('attachments').add(attachment); 2: return attachment; }3: function $gc(key, value){if (arguments.length == 1){return globalChannelMap.get(key); }else if (arguments.length == 2){globalChannelMap.put(key, value); }}function $g(key, value){if (arguments.length == 1){return globalMap.get(key); }else if (arguments.length == 2){globalMap.put(key, value); }}function doScript() {4: // Modify the message variable below to pre process data5: if (messageObject)6: logger.info('messageObject exists');7: return message; 8: }LINE NUMBER: 5DETAILS: ReferenceError: "messageObject" is not defined. at faf8272e-b76d-4cd6-984f-55b23cdb21de_Preprocessor:5 (doScript) at faf8272e-b76d-4cd6-984f-55b23cdb21de_Preprocessor:9

Mirth Project | Nick Rupley | 3 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    Try the following in a 2.x preprocessor: \\ \\ {code}logger.info(typeof messageObject);{code} It outputs "undefined", as expected. However in 3.x it will now throw an error: \\ \\ {code}[2014-03-03 09:09:23,887] ERROR (com.mirth.connect.server.util.javascript.JavaScriptUtil:464): Error executing Preprocessor script from channel: 880e07cc-0729-42c5-a146-29c4b3253f9c com.mirth.connect.server.MirthJavascriptTransformerException: SOURCE CODE: 187: }188: }189: function doScript() {190: // Modify the message variable below to pre process data191: 192: logger.info(typeof messageObject);193: 194: return message; 195: }LINE NUMBER: 192DETAILS: Invalid JavaScript value of type com.mirth.connect.server.userutil.MessageObject at 880e07cc-0729-42c5-a146-29c4b3253f9c_Preprocessor:192 (doScript) at 880e07cc-0729-42c5-a146-29c4b3253f9c_Preprocessor:196 at com.mirth.connect.server.util.javascript.JavaScriptUtil.executeScript(JavaScriptUtil.java:489) at com.mirth.connect.server.util.javascript.JavaScriptUtil.executePreprocessorScripts(JavaScriptUtil.java:183) at com.mirth.connect.server.transformers.JavaScriptPreprocessor$JavaScriptPreProcessorTask.call(JavaScriptPreprocessor.java:57) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:724){code} \\ \\ In addition, try this code: \\ \\ {code}if (messageObject) logger.info('messageObject exists');{code} In 2.x, it throws an error: \\ \\ {code}[2014-03-03 09:14:51,142] ERROR (com.mirth.connect.server.util.JavaScriptUtil:264): Error executing Preprocessor script from channel: faf8272e-b76d-4cd6-984f-55b23cdb21de com.mirth.connect.server.MirthJavascriptTransformerException: SOURCE CODE: 1: String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,"").replace(/^\t+|\t+$/g,""); };function $(string) { if (globalChannelMap.containsKey(string)) { return globalChannelMap.get(string);} else if (globalMap.containsKey(string)) { return globalMap.get(string);} else { return ''; }}function addAttachment(data, type) {var attachment = Packages.com.mirth.connect.server.controllers.MessageObjectController.getInstance().createAttachment(data, type);muleContext.getProperties().get('attachments').add(attachment); 2: return attachment; }3: function $gc(key, value){if (arguments.length == 1){return globalChannelMap.get(key); }else if (arguments.length == 2){globalChannelMap.put(key, value); }}function $g(key, value){if (arguments.length == 1){return globalMap.get(key); }else if (arguments.length == 2){globalMap.put(key, value); }}function doScript() {4: // Modify the message variable below to pre process data5: if (messageObject)6: logger.info('messageObject exists');7: return message; 8: }LINE NUMBER: 5DETAILS: ReferenceError: "messageObject" is not defined. at faf8272e-b76d-4cd6-984f-55b23cdb21de_Preprocessor:5 (doScript) at faf8272e-b76d-4cd6-984f-55b23cdb21de_Preprocessor:9 at com.mirth.connect.server.util.JavaScriptUtil.executeScript(JavaScriptUtil.java:289) at com.mirth.connect.server.util.JavaScriptUtil.executePreprocessorScripts(JavaScriptUtil.java:166) at com.mirth.connect.server.mule.transformers.JavaScriptPreprocessor.transform(JavaScriptPreprocessor.java:40) at org.mule.transformers.AbstractEventAwareTransformer.doTransform(AbstractEventAwareTransformer.java:48) at org.mule.transformers.AbstractTransformer.transform(AbstractTransformer.java:197) at org.mule.impl.MuleEvent.getTransformedMessage(MuleEvent.java:251) at org.mule.routing.inbound.SelectiveConsumer.isMatch(SelectiveConsumer.java:61) at org.mule.routing.inbound.InboundMessageRouter.route(InboundMessageRouter.java:79) at org.mule.providers.AbstractMessageReceiver$DefaultInternalMessageListener.onMessage(AbstractMessageReceiver.java:487) at org.mule.providers.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:266) at org.mule.providers.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:225) at com.mirth.connect.connectors.vm.VMMessageReceiver.getMessages(VMMessageReceiver.java:222) at org.mule.providers.TransactedPollingMessageReceiver.poll(TransactedPollingMessageReceiver.java:108) at org.mule.providers.PollingMessageReceiver.run(PollingMessageReceiver.java:97) at org.mule.impl.work.WorkerContext.run(WorkerContext.java:290) at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1061) at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:575) at java.lang.Thread.run(Thread.java:724){code} However in 3.x you now get warnings from Rhino: \\ \\ {code}[2014-03-03 09:14:40,233] ERROR (Server:146): RHINO USAGE WARNING: Missed Context.javaToJS() conversion: [2014-03-03 09:14:40,233] ERROR (Server:146): Rhino runtime detected object message 9-0 (RECEIVED) of class com.mirth.connect.server.userutil.MessageObject where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.{code}

    Mirth Project | 3 years ago | Nick Rupley
    com.mirth.connect.server.MirthJavascriptTransformerException: SOURCE CODE: 1: String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,"").replace(/^\t+|\t+$/g,""); };function $(string) { if (globalChannelMap.containsKey(string)) { return globalChannelMap.get(string);} else if (globalMap.containsKey(string)) { return globalMap.get(string);} else { return ''; }}function addAttachment(data, type) {var attachment = Packages.com.mirth.connect.server.controllers.MessageObjectController.getInstance().createAttachment(data, type);muleContext.getProperties().get('attachments').add(attachment); 2: return attachment; }3: function $gc(key, value){if (arguments.length == 1){return globalChannelMap.get(key); }else if (arguments.length == 2){globalChannelMap.put(key, value); }}function $g(key, value){if (arguments.length == 1){return globalMap.get(key); }else if (arguments.length == 2){globalMap.put(key, value); }}function doScript() {4: // Modify the message variable below to pre process data5: if (messageObject)6: logger.info('messageObject exists');7: return message; 8: }LINE NUMBER: 5DETAILS: ReferenceError: "messageObject" is not defined. at faf8272e-b76d-4cd6-984f-55b23cdb21de_Preprocessor:5 (doScript) at faf8272e-b76d-4cd6-984f-55b23cdb21de_Preprocessor:9
  2. 0

    Try the following in a 2.x preprocessor: \\ \\ {code}logger.info(typeof messageObject);{code} It outputs "undefined", as expected. However in 3.x it will now throw an error: \\ \\ {code}[2014-03-03 09:09:23,887] ERROR (com.mirth.connect.server.util.javascript.JavaScriptUtil:464): Error executing Preprocessor script from channel: 880e07cc-0729-42c5-a146-29c4b3253f9c com.mirth.connect.server.MirthJavascriptTransformerException: SOURCE CODE: 187: }188: }189: function doScript() {190: // Modify the message variable below to pre process data191: 192: logger.info(typeof messageObject);193: 194: return message; 195: }LINE NUMBER: 192DETAILS: Invalid JavaScript value of type com.mirth.connect.server.userutil.MessageObject at 880e07cc-0729-42c5-a146-29c4b3253f9c_Preprocessor:192 (doScript) at 880e07cc-0729-42c5-a146-29c4b3253f9c_Preprocessor:196 at com.mirth.connect.server.util.javascript.JavaScriptUtil.executeScript(JavaScriptUtil.java:489) at com.mirth.connect.server.util.javascript.JavaScriptUtil.executePreprocessorScripts(JavaScriptUtil.java:183) at com.mirth.connect.server.transformers.JavaScriptPreprocessor$JavaScriptPreProcessorTask.call(JavaScriptPreprocessor.java:57) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:724){code} \\ \\ In addition, try this code: \\ \\ {code}if (messageObject) logger.info('messageObject exists');{code} In 2.x, it throws an error: \\ \\ {code}[2014-03-03 09:14:51,142] ERROR (com.mirth.connect.server.util.JavaScriptUtil:264): Error executing Preprocessor script from channel: faf8272e-b76d-4cd6-984f-55b23cdb21de com.mirth.connect.server.MirthJavascriptTransformerException: SOURCE CODE: 1: String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,"").replace(/^\t+|\t+$/g,""); };function $(string) { if (globalChannelMap.containsKey(string)) { return globalChannelMap.get(string);} else if (globalMap.containsKey(string)) { return globalMap.get(string);} else { return ''; }}function addAttachment(data, type) {var attachment = Packages.com.mirth.connect.server.controllers.MessageObjectController.getInstance().createAttachment(data, type);muleContext.getProperties().get('attachments').add(attachment); 2: return attachment; }3: function $gc(key, value){if (arguments.length == 1){return globalChannelMap.get(key); }else if (arguments.length == 2){globalChannelMap.put(key, value); }}function $g(key, value){if (arguments.length == 1){return globalMap.get(key); }else if (arguments.length == 2){globalMap.put(key, value); }}function doScript() {4: // Modify the message variable below to pre process data5: if (messageObject)6: logger.info('messageObject exists');7: return message; 8: }LINE NUMBER: 5DETAILS: ReferenceError: "messageObject" is not defined. at faf8272e-b76d-4cd6-984f-55b23cdb21de_Preprocessor:5 (doScript) at faf8272e-b76d-4cd6-984f-55b23cdb21de_Preprocessor:9 at com.mirth.connect.server.util.JavaScriptUtil.executeScript(JavaScriptUtil.java:289) at com.mirth.connect.server.util.JavaScriptUtil.executePreprocessorScripts(JavaScriptUtil.java:166) at com.mirth.connect.server.mule.transformers.JavaScriptPreprocessor.transform(JavaScriptPreprocessor.java:40) at org.mule.transformers.AbstractEventAwareTransformer.doTransform(AbstractEventAwareTransformer.java:48) at org.mule.transformers.AbstractTransformer.transform(AbstractTransformer.java:197) at org.mule.impl.MuleEvent.getTransformedMessage(MuleEvent.java:251) at org.mule.routing.inbound.SelectiveConsumer.isMatch(SelectiveConsumer.java:61) at org.mule.routing.inbound.InboundMessageRouter.route(InboundMessageRouter.java:79) at org.mule.providers.AbstractMessageReceiver$DefaultInternalMessageListener.onMessage(AbstractMessageReceiver.java:487) at org.mule.providers.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:266) at org.mule.providers.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:225) at com.mirth.connect.connectors.vm.VMMessageReceiver.getMessages(VMMessageReceiver.java:222) at org.mule.providers.TransactedPollingMessageReceiver.poll(TransactedPollingMessageReceiver.java:108) at org.mule.providers.PollingMessageReceiver.run(PollingMessageReceiver.java:97) at org.mule.impl.work.WorkerContext.run(WorkerContext.java:290) at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1061) at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:575) at java.lang.Thread.run(Thread.java:724){code} However in 3.x you now get warnings from Rhino: \\ \\ {code}[2014-03-03 09:14:40,233] ERROR (Server:146): RHINO USAGE WARNING: Missed Context.javaToJS() conversion: [2014-03-03 09:14:40,233] ERROR (Server:146): Rhino runtime detected object message 9-0 (RECEIVED) of class com.mirth.connect.server.userutil.MessageObject where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.{code}

    Mirth Project | 3 years ago | Nick Rupley
    com.mirth.connect.server.MirthJavascriptTransformerException: SOURCE CODE: 1: String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,"").replace(/^\t+|\t+$/g,""); };function $(string) { if (globalChannelMap.containsKey(string)) { return globalChannelMap.get(string);} else if (globalMap.containsKey(string)) { return globalMap.get(string);} else { return ''; }}function addAttachment(data, type) {var attachment = Packages.com.mirth.connect.server.controllers.MessageObjectController.getInstance().createAttachment(data, type);muleContext.getProperties().get('attachments').add(attachment); 2: return attachment; }3: function $gc(key, value){if (arguments.length == 1){return globalChannelMap.get(key); }else if (arguments.length == 2){globalChannelMap.put(key, value); }}function $g(key, value){if (arguments.length == 1){return globalMap.get(key); }else if (arguments.length == 2){globalMap.put(key, value); }}function doScript() {4: // Modify the message variable below to pre process data5: if (messageObject)6: logger.info('messageObject exists');7: return message; 8: }LINE NUMBER: 5DETAILS: ReferenceError: "messageObject" is not defined. at faf8272e-b76d-4cd6-984f-55b23cdb21de_Preprocessor:5 (doScript) at faf8272e-b76d-4cd6-984f-55b23cdb21de_Preprocessor:9

    Root Cause Analysis

    1. com.mirth.connect.server.MirthJavascriptTransformerException

      SOURCE CODE: 1: String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,"").replace(/^\t+|\t+$/g,""); };function $(string) { if (globalChannelMap.containsKey(string)) { return globalChannelMap.get(string);} else if (globalMap.containsKey(string)) { return globalMap.get(string);} else { return ''; }}function addAttachment(data, type) {var attachment = Packages.com.mirth.connect.server.controllers.MessageObjectController.getInstance().createAttachment(data, type);muleContext.getProperties().get('attachments').add(attachment); 2: return attachment; }3: function $gc(key, value){if (arguments.length == 1){return globalChannelMap.get(key); }else if (arguments.length == 2){globalChannelMap.put(key, value); }}function $g(key, value){if (arguments.length == 1){return globalMap.get(key); }else if (arguments.length == 2){globalMap.put(key, value); }}function doScript() {4: // Modify the message variable below to pre process data5: if (messageObject)6: logger.info('messageObject exists');7: return message; 8: }LINE NUMBER: 5DETAILS: ReferenceError: "messageObject" is not defined. at faf8272e-b76d-4cd6-984f-55b23cdb21de_Preprocessor:5 (doScript) at faf8272e-b76d-4cd6-984f-55b23cdb21de_Preprocessor:9

      at com.mirth.connect.server.util.JavaScriptUtil.executeScript()
    2. com.mirth.connect
      JavaScriptPreprocessor.transform
      1. com.mirth.connect.server.util.JavaScriptUtil.executeScript(JavaScriptUtil.java:289)
      2. com.mirth.connect.server.util.JavaScriptUtil.executePreprocessorScripts(JavaScriptUtil.java:166)
      3. com.mirth.connect.server.mule.transformers.JavaScriptPreprocessor.transform(JavaScriptPreprocessor.java:40)
      3 frames
    3. org.mule.transformers
      AbstractTransformer.transform
      1. org.mule.transformers.AbstractEventAwareTransformer.doTransform(AbstractEventAwareTransformer.java:48)
      2. org.mule.transformers.AbstractTransformer.transform(AbstractTransformer.java:197)
      2 frames
    4. org.mule.impl
      MuleEvent.getTransformedMessage
      1. org.mule.impl.MuleEvent.getTransformedMessage(MuleEvent.java:251)
      1 frame
    5. org.mule.routing
      InboundMessageRouter.route
      1. org.mule.routing.inbound.SelectiveConsumer.isMatch(SelectiveConsumer.java:61)
      2. org.mule.routing.inbound.InboundMessageRouter.route(InboundMessageRouter.java:79)
      2 frames
    6. org.mule.providers
      AbstractMessageReceiver.routeMessage
      1. org.mule.providers.AbstractMessageReceiver$DefaultInternalMessageListener.onMessage(AbstractMessageReceiver.java:487)
      2. org.mule.providers.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:266)
      3. org.mule.providers.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:225)
      3 frames
    7. com.mirth.connect
      VMMessageReceiver.getMessages
      1. com.mirth.connect.connectors.vm.VMMessageReceiver.getMessages(VMMessageReceiver.java:222)
      1 frame
    8. org.mule.providers
      PollingMessageReceiver.run
      1. org.mule.providers.TransactedPollingMessageReceiver.poll(TransactedPollingMessageReceiver.java:108)
      2. org.mule.providers.PollingMessageReceiver.run(PollingMessageReceiver.java:97)
      2 frames
    9. org.mule.impl
      WorkerContext.run
      1. org.mule.impl.work.WorkerContext.run(WorkerContext.java:290)
      1 frame
    10. Backport of JSR 166
      ThreadPoolExecutor$Worker.run
      1. edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1061)
      2. edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:575)
      2 frames
    11. Java RT
      Thread.run
      1. java.lang.Thread.run(Thread.java:724)
      1 frame