Yossi Dahan [BizTalk]

Google
 

Friday, November 25, 2005

Merging two messages in BizTalk 2004 (continued)

In my second post, back in July, I was writing about my problem merging two documents.
It was only today when I got an email with questions about it that I realised I forgot to write how I eventually solved it.

It turned out to be much simpler then I imagined.

For those of you who are too lazy to follow the link and find out what the original problem was here's a (very) brief description - I'm receiving two messages into an orchestration each contains a list of items, each has a different subset of information about those items.
What I needed was a single message with all the fields of all the items.

Before I go on describing the solution I'll give the bottom line (for the sake of those not interested in the details) - the solution was using custom xslt in a map generated by the transform shape.

And now for the details -

I've placed a transform shape in the process (inside a construct message shape, of course)
Kindly asked the transform shape to generate a map for me (by selecting the New map radio button) and then set the two recieved input messages as the source of the transform.
The destination of the transform was set to the single output message defined in the orchestration.

In case you're wondering what happens when you configure the transform message with two source messages - BizTalk generates a map where the source schema is a generated schema that has a root node creatively named "Root" with child nodes - InputMessagePart_0 and InputMessagePart_1 (add more source messages and you get more "parts")

The destination of the generated map is simply the schema of the configued message. not magic needed here.

I let BizTalk generate that magic map for me and half of the solution's done.

The other half is all about mapping from that combined source schema to the destination schema, quite standard work for a seasoned BizTalker.

Theoretically I could now map the source to the destination using the mapper, functoids etc.
Only that refering from a node in the first part to the correct node in the 2nd part is not simple unless you want to rely on the records appearing exactly in the same order in both messages which I don't think is a very bright idea.

The way I chose to approach this was ignoring the mapper altogether and using custom xslt script.
Initially I've tried doing this with the mapper and inline xslt scripts, but performance wasn't brilliant (to be gentle) moving everything to my own custom xslt did the job nicely.
(If can read more about my opnion on the mapper vs. xslt question here)

I kept the map BizTalk generated for me (in my case I had to move it to the maps assembly though) but did not use the mapper tool to perform the transform, instead I've created an xslt transformation to convert that generated combined source to the destination.

As you probably know when in XSLT it's quite easy to point whereever you need in the document so refering from one node to another was an easy task so 10 minutes later and I had a map, using custom xslt to combine the two messages.

changed the transform shape to use that map (I've moved the generated one to a references assembly, remember?), deployed and tested - worked first time. :-)


Quite simple once you know it, makes we wonder why I didn't think about it in the first place.