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).
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
- 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 whosecontentis the message, read and written as in a JavaScript step; otherwise a copy of the input),connectorMessage.getEncodedData()andgetRawData()(the message text, read as the SMTP Sender's${message}is), Mirth's variable maps (channelMap,responseMap,$(),logger),ResponseFactory,ResponseandStatus, and the Mirth APIs a JavaScript step has:router.routeMessage,DatabaseConnectionFactory,FileUtil,DateUtiland the rest, with the same limits, andhttp.requestto call an HTTP API through a Generic REST profile. - The return value is the response. A
Response(fromResponseFactory.getSentResponse(),getErrorResponse(),getQueuedResponse(),getFilteredResponse()ornew Response(status, message)) or aStatussets the status. Anything else is the response message, with statusSENT. - With no return value, the last
Responsethe script put inresponseMapsets the status. With none, the status isSENT. ERRORfails the step (its error handling applies);QUEUEDfails it as not sent, so it is retried;SENTandFILTEREDsucceed. A thrown error fails the step.- 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.
| Action | What it does | Step parameters | Keys a message may supply |
|---|---|---|---|
send | Run 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.
{
"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
configurationMapreads come back empty, andglobalMapwrites are not kept (the result counts them inglobalWritesIgnored). 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,ChannelUtiland others) do not exist in the sandbox; the importer names each one a script uses in its findings. The E4X-style accessmsg['PID']['PID.5']works. - A script is at most 256 KB.