1
votes

Please could somebody confirm the following.. I am using Mirth Connect 3.5.08232. My Source Connector is a Database Reader.

Say, I am using a query that returns multiple rows, and return the result (via JavaScript), as documentation suggests, so that Mirth would treat each row as a separate message. I also use a couple of mappers as source transformers, and save the mapped fields in my channel map (which ends up to contain only those fields that I define in transformers)

In the destination, and specifically, in destination response transformer (or destination body, if it is a JavaScript writer), how do I access the source fields?

the only way I found by trial and error is

var rawMsg = connectorMessage.getRawData();
var xmlMsg = new XML(rawMsg);
logger.info(xmlMsg.some_field); // ignore the root element of rawMsg

Is this the right way to do this? I thought that maybe the fields that were nicely automatically detected would be put in some kind of a map, like sourceMap - but that doesn't seem to be the case, right?

Thank you

1

1 Answers

3
votes

If you are using Mapper steps in your transformer to extract the data and put it into a variable map (like the channel map), then you can use any of the following methods to retrieve it from a subsequent JavaScript context (including a JavaScript Writer, and your response transformer):

var value = channelMap.get('key');
var value = $c('key');
var value = $('key');

Look at the Variable Maps section of the User Guide for more information.

So to recap, say you're selecting a column "mycolumn" with a Database Reader. The XML sent to the channel will be something like this:

<result>
    <mycolumn>value</mycolumn>
</result>

Then you can choose to extract pieces of that message into specific variables for later use. The transformer allows you to easily drag-and-drop pieces of the sample inbound message. Mapper Transformer Step

Finally in your JavaScript Writer (or in any subsequent filter, transformer, or response transformer), just drag the value into the field you want: JavaScript Writer

And the corresponding JavaScript code will automatically be inserted: Inserted Code

One last note, if you are selecting a lot of variables and don't want to make Mapper steps for each one individually, you can use a JavaScript Step to iterate through the message and extract each column into a separate map variable:

for each (child in msg.children()) {
    channelMap.put(child.localName(), child.toString());
}

Or, you can just reference the columns directly from within the JavaScript Writer:

var msg = new XML(connectorMessage.getEncodedData());

var column1 = msg.column1.toString();
var column2 = msg.column2.toString();
...