Taction Software — FHIR Integration with Mirth Connect
Blog·June 12, 2026·Taction Software

Mirth Connect JavaScript and Groovy Transformer Errors

Transformers are where most custom logic — and most custom bugs — live in Mirth Connect. A transformer exception can push messages to ERROR, corrupt output, or silently drop data. The good news: Mirth tells you the line and the error; you just need to read it correctly.

Mirth ConnectTransformersJavaScriptGroovyTroubleshooting
TL;DR

Open the errored message and read the stack trace — Mirth reports the transformer step and line number. The most common cause is a TypeError from reading a segment or field that isn't present in that particular message: HL7 is variable, so guard every access. The second most common: writing to msg when you meant tmp.

A transformer breaking your production feed?

Senior Mirth engineers debug JavaScript/Groovy fast — 15-minute response on Silver and above.

A transformer exception can silently drop or corrupt clinical data. If messages are erroring in production right now, get an engineer on it in parallel.

Get Help With a Broken Interface →

Read the error first

Open the errored message in the Dashboard and read the stack trace. Mirth reports the transformer step and the line number. The most common errors:

1. TypeError: cannot read property of undefined / null.You're reading a segment or field that isn't present in this particular message. HL7 is variable — not every message has every segment or repetition. Guard your access: check the segment exists before reading it, rather than assuming msg['OBX']['OBX.5']['OBX.5.1'] is always there.

2. Referencing msg vs tmp incorrectly. In a transformer, msg is the inbound message and tmp is the outbound template. Writing to msg when you meant tmp(or reading the wrong one) is a frequent logic bug that produces wrong output without throwing an error. Confirm you're reading from msg and writing to tmp.

3. E4X / XML access mistakes (HL7 v2 in Mirth). Mirth represents parsed messages as E4X XML. Indexing repeating segments or fields incorrectly (or treating a single value as a list) throws errors or returns unexpected nodes. Use the correct repetition index, and convert nodes to strings with .toString() when you need a plain value.

4. Using Java/Groovy APIs that aren't imported. In Groovy transformers, calling a class without importing it fails. Add the import, or use the fully qualified class name.

5. Date, number, and encoding conversions.Parsing an HL7 date that's empty or in an unexpected format throws. Validate before converting and handle empty values explicitly.

6. Channel map / global map key errors. Reading a map variable that was never set returns null and then errors downstream. Set defaults and check for null.

Step-by-step debugging

  1. Open the errored message; note the transformer step and line.
  2. Add a logger.info() (or logger.debug()) statement just before the failing line to print the value you're accessing — view it in the server log.
  3. Confirm the segment/field actually exists in thismessage; test with the specific message that failed, not a "happy path" sample.
  4. Add a null/existence guard around the access.
  5. Verify you're reading msg and writing tmp.
  6. Reprocess the failed message to confirm the fix.

How to prevent it

Write transformers defensively: never assume a segment or repetition exists, set map defaults, and convert nodes to strings explicitly. Test against real production message samples — including the malformed and partial ones — not just clean examples. Keep transformer code in version control (your own Git repo) so changes are reviewable. If you need senior hands on channel work, you can hire a Mirth Connect developer.

Can't pin down the transformer bug?

Send us the script and a failing message — we'll find it and harden the channel.

Get Help With a Broken Interface →
FAQ

Frequently Asked Questions

Why does my Mirth transformer throw "TypeError: cannot read property"?
You're reading a segment or field that isn't present in that message. HL7 messages vary; guard the access by checking the segment exists before reading it.
What's the difference between msg and tmp in a Mirth transformer?
msg is the inbound message you read from; tmp is the outbound template you write to. Mixing them up is a common cause of wrong output.
How do I see the value a transformer is working with?
Add a logger.info() statement before the failing line and read the server log, or use the message browser to inspect the encoded/transformed content for the failed message.

Need expert Mirth Connect support?

Whether you have a one-time integration project or need ongoing managed support, every engagement is named, scoped, and priced upfront — productized packages, no hourly billing.

Talk to a Mirth Solutions Architect

60-second form. Senior engineer responds within one business day.

What is 3 + 4 ?