简体   繁体   中英

Mirth channelMap in source JavaScript

In my source connector, I'm using javascript for my database work due to my requirements and parameters.

The end result is storing the data.

ifxResults = ifxConn.executeCachedQuery(ifxQuery); //var is declared 

I need to use these results in the destination transformer.

I have tried channelMap.put("results", ifxResults); .

I get the following error ReferenceError: "channelMap" is not defined.

I have also tried to use return ifxResults but I'm not sure how to access this in the destination transformer.

Do you want to send each row as a separate message through your channel? If so, sounds like you want to use the Database Reader in JavaScript mode. Just return that ResultSet (it's really a CachedRowSet if you use executeCachedQuery like that) and the channel will handle the rest, dispatching an XML representation of each row as discrete messages.

If you want to send all rows in the result set aggregated into a single message, that will be possible with the Database Reader very soon: MIRTH-2337

Mirth Connect 3.5 will be released next week so you can take advantage of it then. But if you can't wait or don't want to upgrade then you can still do this with a JavaScript Reader:

var processor = new org.apache.commons.dbutils.BasicRowProcessor();
var results = new com.mirth.connect.donkey.util.DonkeyElement('<results/>');

while (ifxResults.next()) {
    var result = results.addChildElement('result');
    for (var entries = processor.toMap(ifxResults).entrySet().iterator(); entries.hasNext();) {
        var entry = entries.next();
        result.addChildElement(entry.getKey(), java.lang.String.valueOf(entry.getValue()));
    }
}

return results.toXml();

I know this question is kind of old, but here's an answer just for the record.

For this answer, I'm assuming that you are using a Source connector type of JavaScript Reader , and that you're trying to use channelMap in the JavaScript Reader Settings editing pane.

The problem is that the channelMap variable isn't available in this part of the channel. It's only available in filters and transformers.

It's possible that what you want can be accomplished by using the globalChannelMap variable, eg

globalChannelMap.put("results", ifxResults);

I usually need to do this when I'm processing one record at a time and need to pass some setting to the destination channel. If you do it like I've done in the past, then you would first create a globalChannelMap key/value in the source channel's transformer:

globalchannelMap.put("ProcID","TestValue");

Then go to the Destinations tab and select your destination channel to make sure you're sending it to the destination (I've never tried this for channels with multiple destinations, so I'm not sure if anything different needs to be done).

Destination tab of source channel

Notice that ProcID is now listed in the Destination Mappings box. Click the New button next to the Map Variable box and you'll see Variable 1 appear. Double click on that and put in your mapping key, which in this case is ProcID.

Now go to your destination channel's source transformer. There you would enter the following code:

var SentValue = sourceMap.get("ProcID");

Now SentValue in your destination transformer has whatever was in ProcID when your source channel relinquished control.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM