How do you debug Javascript code in Mirth Connect?
Asked Answered
D

3

9

I am trying to create a library of functions in Mirth Connect, using Code Templates. Using logger.debug is painful. I tried copying the code to a dummy HTML page and use browser's debugging tools. Unfortunately, the javascript engines in Mirth v/s those in browsers are different and Mirth Javascript uses several deprecated syntax.

How do I debug or step through Javascript code in Mirth Connect?

Devoe answered 8/9, 2020 at 18:30 Comment(0)
G
2

You can use the Rhino debugger in embedded mode....its has some little nuances to it, but i think this is what your looking for.

Here is a thread to walk you through the process.

https://forums.mirthproject.io/forum/mirth-connect/support/7210-real-debugging-for-mirth-javascript-channel-code

Greenheart answered 9/9, 2020 at 0:10 Comment(3)
Unfortunately I dont have access to the server hosting Mirth :-(Devoe
Are you using a mirth appliance?Greenheart
It's a VM but I dont have access to remote in.Devoe
E
4

All Versions of Mirth Connect

"When in doubt, log it out"

There are a few ways to do this in Mirth Connect without access to the application config, its logs, or the host:

  1. Make calls to logger. In your case, since you don't have access to the server, you will have to do this as logger.error("your data") as the logger level is set at the server in log4j.properties. These will be visible in the MC dashboard which provides a partial view of the log. A good practice would be to prepend your logger statement with the location from where it came from, for example logger.info(channelName + " transformer step 1 " + "your other data") otherwise other team members may be left wondering what channel originated the log message on the console.
  2. Use the Mirth Connect maps to log detailed information about variable values. Be wary of this as putting large objects in maps, particularly the channelMap and globalChannelMap will make your message payloads excessively large. Of course you can also use channel map variables to store informational data like you hit a piece of code. For example: $c('patient is in table', true) which is also the same as channelMap.put('patient is in table', true)
  3. At the extreme end, you can intentionally overwrite your messages with only debug data. This is useful in cases where you need to log out large objects. It adds a lot of complexity to your debugging though.

For either case make your recorded values:

  • only recorded when a debug flag is set - this ensures your logging and debugging is not spamming data out when you are not actively needing to capture the data
  • have meaningful messages - Don't just log out "x = 12", log out "MsgId: " + msg.getMessageId() + " in method foobar() had x = 12"

New in Mirth Connect 4.0

MC 4.0 introduced a means to launch the Rhino Debugger from Mirth connect. See the release notes for MC 4.0 to learn how to use it.

Endymion answered 16/9, 2020 at 22:49 Comment(0)
G
2

You can use the Rhino debugger in embedded mode....its has some little nuances to it, but i think this is what your looking for.

Here is a thread to walk you through the process.

https://forums.mirthproject.io/forum/mirth-connect/support/7210-real-debugging-for-mirth-javascript-channel-code

Greenheart answered 9/9, 2020 at 0:10 Comment(3)
Unfortunately I dont have access to the server hosting Mirth :-(Devoe
Are you using a mirth appliance?Greenheart
It's a VM but I dont have access to remote in.Devoe
A
2

In the new version of Mirth 4.0 you can debug your javascript through the admin console https://github.com/nextgenhealthcare/connect/wiki/4.0.0---What%27s-New

Algo answered 29/6, 2022 at 8:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.