2

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

hello_earth
  • 1,442
  • 1
  • 25
  • 39

1 Answers1

4

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();
...
Nick Rupley
  • 1,028
  • 7
  • 8
  • thank you for your reply - and for your many posts on the mirth support site. in the particular case, i rather wished for all the variables to be somehow mapped automatically - in fact it IS done - it is just that the way to get them is through the serialized internal representation of the raw input message. - the reason I was wondering is that there may be lots and lots of variables - and it would be so tedious to add them one by one. but anyway - if there is no such way (or a way to create mappings for all input fields automatially, say) then I'll gladly mark your answer as THE answer. – hello_earth Aug 10 '17 at 15:01
  • 1
    You certainly don't have to create Mapper steps individually if you have a lot of them. Using a JavaScript step you can map everything automatically, for example. I updated my answer to note that. – Nick Rupley Aug 10 '17 at 15:23