Question

In Channel A i am getting XML as input.Incoming XML mentioned below:

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<bookstore>
<books>
<book>
<title>SpringInAction</title>
<NoOfCopies>10</NoOfCopies>
</book>
<book>
<title>HibernateInAction</title>
<NoOfCopies>8</NoOfCopies>
</book>
<book>
<title>JSFInAction</title>
<NoOfCopies>5</NoOfCopies>
</book>
<book>
<title>StrutsInAction</title>
<NoOfCopies>9</NoOfCopies>
</book>
<book>
<title>JSPInAction</title>
<NoOfCopies>4</NoOfCopies>
</book>
</books>
</bookstore>

I am parsing this XML in Edit Transformer of the Source and making JavaScript object and putting this JavaScript object into a channel Map like this:

var book=new Object();
book.title = msg['books']['book'][0]['title'].toString();
book.copies = msg['books']['book'][0]['NoOfCopies'].toString();
logger.info("book "+book);
channelMap.put("book",book);

Now i want to pass this JavaScript object to other Channel B from destination of Channel A and Channel B receives this JavaScript object as input and does the rest of the processing .Is it possible in Mirth?

I am using Mirth Version 2.2.1.5861.

Was it helpful?

Solution

Before saving the channel variable, serialize it (json object).

In your channel destination, write out the "book" variable.

So something like this:

In Transformer

var book=new Object();
book.title = msg['books']['book'][0]['title'].toString();
book.copies = msg['books']['book'][0]['NoOfCopies'].toString();
logger.info("book "+book);

var Jbook = JSON.stringify(book);
channelMap.put("Jbook",Jbook );

In Destination Template

${jbook}

Then on the receiving channel

var book = JSON.parse(msg.toString());

I have not verified this code, but it should give you a coding strategy.

See Mirth Discussion about JSON

Also: Please see our HealthcareIT project proposal at area51.StackExchange. This would be a good question to ask.

OTHER TIPS

Objects can be passed using the Global Channel Map. Other two maps are persisted to the database and therefore the Mirth Connect engine serializes them to strings. However, for the Global Channel Map you should handle the context in your script (as the name suggests, it exists not only in a message or channel context).

There is a sample of passing the object using the Global Channel Map here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top