Skip to content
Reference

Adapter: JavaScript Writer

Run the step's JavaScript in the sandbox as a destination; its return value or responseMap sets the response status (Mirth JavaScript Writer).

On this page

Purpose

Run a script as a destination, as the Mirth JavaScript Writer does. The script is on the step (script) and runs once per message in the workflow sandbox (isolated-vm), with the same memory and time limits as a JavaScript step. Its only network access is http.request, through a Generic REST profile. The Mirth importer maps JavaScript Writers to it and keeps the script as written.

Auth

None. The profile has no settings; create one profile and use it for every JavaScript Writer step.

How a send works

  1. The script sees msg (the step input as Mirth's message tree when it is HL7 v2 or XML text, an MLLP payload, or a file/SFTP pickup run whose content is the message, read and written as in a JavaScript step; otherwise a copy of the input), connectorMessage.getEncodedData() and getRawData() (the message text, read as the SMTP Sender's ${message} is), Mirth's variable maps (channelMap, responseMap, $(), logger), ResponseFactory, Response and Status, and the Mirth APIs a JavaScript step has: router.routeMessage, DatabaseConnectionFactory, FileUtil, DateUtil and the rest, with the same limits, and http.request to call an HTTP API through a Generic REST profile.
  2. The return value is the response. A Response (from ResponseFactory.getSentResponse(), getErrorResponse(), getQueuedResponse(), getFilteredResponse() or new Response(status, message)) or a Status sets the status. Anything else is the response message, with status SENT.
  3. With no return value, the last Response the script put in responseMap sets the status. With none, the status is SENT.
  4. ERROR fails the step (its error handling applies); QUEUED fails it as not sent, so it is retried; SENT and FILTERED succeed. A thrown error fails the step.
  5. The step returns { status, response, statusMessage?, responseMap? }.

Settings

Auth is none. Dotted names are fields inside an object setting. Secret settings are encrypted at rest, never returned by a read, and shown masked in the console and in exports; their defaults are not shown.

This adapter has no settings.

Actions

A trailing ? marks an optional step parameter. A message can supply only the keys in the last column; everything else comes from the step.

ActionWhat it doesStep parametersKeys a message may supply
sendRun the script once for the message.script, codeTables?None

Minimal example

The smallest profile the engine accepts: the required settings only, with synthetic values. Create it with POST /api/adapter-profiles, then test it with POST /api/adapter-profiles/{id}/test.

json
{
  "name": "JavaScript Writer (example)",
  "adapterType": "javascript-writer",
  "config": {}
}

Limits

  • The script reads only the step input. Workspace variables are not loaded for this step, so configurationMap reads come back empty, and globalMap writes are not kept (the result counts them in globalWritesIgnored). Read variables or write the global map in a JavaScript step before it.
  • Literal E4X syntax, Java classes outside the allowlist and the Mirth utilities not listed there (SMTPConnectionFactory, HTTPUtil, ChannelUtil and others) do not exist in the sandbox; the importer names each one a script uses in its findings. The E4X-style access msg['PID']['PID.5'] works.
  • A script is at most 256 KB.

Reference