com.mirth.connect.server.MirthJavascriptTransformerException: SOURCE CODE: 36: 37: // if it is a valid hl7 segment, we'll 38: // append the new line to the new message 39: logger.error(line); 40: 41: if(line.match(/^[a-zA-Z0-9]{3}\|/)) { 42: // see the first comment 43: if( ! first_iteration){ 44: new_message += '\r'; 45: } LINE NUMBER: 41 DETAILS: TypeError: Cannot find function match in object function $(val) {...}. at 77bdf932-8ebc-4990-b234-b04b9fd89f75_Preprocessor:41 (doScript) at 77bdf932-8ebc-4990-b234-b04b9fd89f75_Preprocessor:72

Mirth Project | Ivan Olmos | 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

    I use the following code in my PreProcessor under a Mirth Connect Channel: // initialize a first_iteration flag. // we don't want to add a carriage return // before the MSH segment var first_iteration = true; // initialize the new message as an empty string var new_message = ''; // loop over each line in the message // by splitting on the hl7 standard carriage return for each (var line in message.split(/\r/)) { // if it is a valid hl7 segment, we'll // append the new line to the new message logger.error(line); if(line.match(/^[a-zA-Z0-9]{3}\|/)) { // see the first comment if( ! first_iteration){ new_message += '\r'; } new_message += line; } else { // if it isn't a valid hl7 segment, // we'll append it to the end of the // previous segment instead new_message += ' ' + line; } // it will never be the first_iteration again first_iteration = false; } logger.error(new_message); new_message = new_message.replace(/[']{1}/gi,"''"); new_message = new_message.replace(/[\x08]{1}/gi,""); //Look for the Backspace character //send the fixed message to the channel message = new_message; return message; I GET THE FOLLOWING ERROR MESSAGE: Preprocessor Script error ERROR MESSAGE: Error running preprocessor scripts com.mirth.connect.server.MirthJavascriptTransformerException: SOURCE CODE: 36: 37: // if it is a valid hl7 segment, we'll 38: // append the new line to the new message 39: logger.error(line); 40: 41: if(line.match(/^[a-zA-Z0-9]{3}\|/)) { 42: // see the first comment 43: if( ! first_iteration){ 44: new_message += '\r'; 45: } LINE NUMBER: 41 DETAILS: TypeError: Cannot find function match in object function $(val) {...}. at 77bdf932-8ebc-4990-b234-b04b9fd89f75_Preprocessor:41 (doScript) at 77bdf932-8ebc-4990-b234-b04b9fd89f75_Preprocessor:72 at com.mirth.connect.server.util.javascript.JavaScriptUtil.executeScript(JavaScriptUtil.java:490) at com.mirth.connect.server.util.javascript.JavaScriptUtil.executePreprocessorScripts(JavaScriptUtil.java:184) at com.mirth.connect.server.transformers.JavaScriptPreprocessor$JavaScriptPreProcessorTask.call(JavaScriptPreprocessor.java:57) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)

    Mirth Project | 3 years ago | Ivan Olmos
    com.mirth.connect.server.MirthJavascriptTransformerException: SOURCE CODE: 36: 37: // if it is a valid hl7 segment, we'll 38: // append the new line to the new message 39: logger.error(line); 40: 41: if(line.match(/^[a-zA-Z0-9]{3}\|/)) { 42: // see the first comment 43: if( ! first_iteration){ 44: new_message += '\r'; 45: } LINE NUMBER: 41 DETAILS: TypeError: Cannot find function match in object function $(val) {...}. at 77bdf932-8ebc-4990-b234-b04b9fd89f75_Preprocessor:41 (doScript) at 77bdf932-8ebc-4990-b234-b04b9fd89f75_Preprocessor:72
  2. 0

    I use the following code in my PreProcessor under a Mirth Connect Channel: // initialize a first_iteration flag. // we don't want to add a carriage return // before the MSH segment var first_iteration = true; // initialize the new message as an empty string var new_message = ''; // loop over each line in the message // by splitting on the hl7 standard carriage return for each (var line in message.split(/\r/)) { // if it is a valid hl7 segment, we'll // append the new line to the new message logger.error(line); if(line.match(/^[a-zA-Z0-9]{3}\|/)) { // see the first comment if( ! first_iteration){ new_message += '\r'; } new_message += line; } else { // if it isn't a valid hl7 segment, // we'll append it to the end of the // previous segment instead new_message += ' ' + line; } // it will never be the first_iteration again first_iteration = false; } logger.error(new_message); new_message = new_message.replace(/[']{1}/gi,"''"); new_message = new_message.replace(/[\x08]{1}/gi,""); //Look for the Backspace character //send the fixed message to the channel message = new_message; return message; I GET THE FOLLOWING ERROR MESSAGE: Preprocessor Script error ERROR MESSAGE: Error running preprocessor scripts com.mirth.connect.server.MirthJavascriptTransformerException: SOURCE CODE: 36: 37: // if it is a valid hl7 segment, we'll 38: // append the new line to the new message 39: logger.error(line); 40: 41: if(line.match(/^[a-zA-Z0-9]{3}\|/)) { 42: // see the first comment 43: if( ! first_iteration){ 44: new_message += '\r'; 45: } LINE NUMBER: 41 DETAILS: TypeError: Cannot find function match in object function $(val) {...}. at 77bdf932-8ebc-4990-b234-b04b9fd89f75_Preprocessor:41 (doScript) at 77bdf932-8ebc-4990-b234-b04b9fd89f75_Preprocessor:72 at com.mirth.connect.server.util.javascript.JavaScriptUtil.executeScript(JavaScriptUtil.java:490) at com.mirth.connect.server.util.javascript.JavaScriptUtil.executePreprocessorScripts(JavaScriptUtil.java:184) at com.mirth.connect.server.transformers.JavaScriptPreprocessor$JavaScriptPreProcessorTask.call(JavaScriptPreprocessor.java:57) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)

    Mirth Project | 3 years ago | Ivan Olmos
    com.mirth.connect.server.MirthJavascriptTransformerException: SOURCE CODE: 36: 37: // if it is a valid hl7 segment, we'll 38: // append the new line to the new message 39: logger.error(line); 40: 41: if(line.match(/^[a-zA-Z0-9]{3}\|/)) { 42: // see the first comment 43: if( ! first_iteration){ 44: new_message += '\r'; 45: } LINE NUMBER: 41 DETAILS: TypeError: Cannot find function match in object function $(val) {...}. at 77bdf932-8ebc-4990-b234-b04b9fd89f75_Preprocessor:41 (doScript) at 77bdf932-8ebc-4990-b234-b04b9fd89f75_Preprocessor:72
  3. 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: 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
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 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: 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

    1 unregistered visitors

    Root Cause Analysis

    1. com.mirth.connect.server.MirthJavascriptTransformerException

      SOURCE CODE: 36: 37: // if it is a valid hl7 segment, we'll 38: // append the new line to the new message 39: logger.error(line); 40: 41: if(line.match(/^[a-zA-Z0-9]{3}\|/)) { 42: // see the first comment 43: if( ! first_iteration){ 44: new_message += '\r'; 45: } LINE NUMBER: 41 DETAILS: TypeError: Cannot find function match in object function $(val) {...}. at 77bdf932-8ebc-4990-b234-b04b9fd89f75_Preprocessor:41 (doScript) at 77bdf932-8ebc-4990-b234-b04b9fd89f75_Preprocessor:72

      at com.mirth.connect.server.util.javascript.JavaScriptUtil.executeScript()
    2. com.mirth.connect
      JavaScriptPreprocessor$JavaScriptPreProcessorTask.call
      1. com.mirth.connect.server.util.javascript.JavaScriptUtil.executeScript(JavaScriptUtil.java:490)
      2. com.mirth.connect.server.util.javascript.JavaScriptUtil.executePreprocessorScripts(JavaScriptUtil.java:184)
      3. com.mirth.connect.server.transformers.JavaScriptPreprocessor$JavaScriptPreProcessorTask.call(JavaScriptPreprocessor.java:57)
      3 frames
    3. Java RT
      Thread.run
      1. java.util.concurrent.FutureTask.run(Unknown Source)
      2. java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      3. java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      4. java.lang.Thread.run(Unknown Source)
      4 frames