Search code examples
datedictionarybiztalkaccumulate

Accumulating Date Elements Across Hierarchies In A BizTalk Map


( Please check my popup note at the bottom of this question before marking me down. Thank you! )

I have a problem in BizTalk where I am only able to achieve my desired mapping through multiple steps and would like to achieve the output using a single map.

An example of my input XML is as follows:-

<Books>
    <Book><Title>The BFG</Title><ISBN>0-224-02040-4</ISBN></Book>
    <Book><Title>The Hobbit</Title><ISBN>978-0261102217</ISBN></Book>
    <Book><Title>BizTalk Server 2010 Unleashed</Title><ISBN>978-0-672-33118-7</ISBN></Book> 
</Books>
<Revisions>
    <Revision><ISBN>0-224-02040-4</ISBN><Version>1</Version><Published>1970-08-22T00:00:00</Published></Revision>
    <Revision><ISBN>0-224-02040-4</ISBN><Version>2</Version><Published>1975-09-25T00:00:00</Published></Revision>
    <Revision><ISBN>0-224-02040-4</ISBN><Version>3</Version><Published>1990-09-16T00:00:00</Published></Revision>
    <Revision><ISBN>978-0-672-33118-7</ISBN><Version>1</Version><Published>2010-03-28T00:00:00</Published></Revision>
    <Revision><ISBN>978-0261102217</ISBN><Version>1</Version><Published>1960-09-25T00:00:00</Published></Revision>
    <Revision><ISBN>978-0-672-33118-7</ISBN><Version>2</Version><Published>2011-09-16T00:00:00</Published></Revision>
<Revisions>

My desired output XML for this example is:-

<HistoricBooks>
    <FirstIssue><ISBN>0-224-02040-4</ISBN><Title>The BFG</Title><FirstPublished>1970-08-22T00:00:00</FirstPublished><FirstIssue>
    <FirstIssue><ISBN>978-0261102217</ISBN><Title>The Hobbit</Title><FirstPublished>1960-09-25T00:00:00</FirstPublished><FirstIssue>
    <FirstIssue><ISBN>978-0-672-33118-7</ISBN><Title>BizTalk Server 2010 Unleashed</Title><FirstPublished>2010-03-28T00:00:00</FirstPublished><FirstIssue>
</HistoricBooks>

The first problem I have encountered is that BizTalk Minimum and CumulativeMinimum functoids both require numeric inputs and won’t work with dates. Therefore the first part of my question is...

What is the best way to perform minimum and maximum functions on date elements in a BizTalk map?

The second problem I have is with the way the cumulative functoids understand scope. The scope parameter indicates the depth at which to accumulate (entire document, parent, grandparent etc) but in this case it is not appropriate to simply take the minimum across all children of <revisions>. I need to be more selective. Therefore the second part of my question is...

Which functoid should I use to perform the accumulation of dates selectively across my XML hierarchies and how should I achieve it?

I am aware this is two-fold question. I am also aware there are a number of ways of achieving the answers but many will result in complex, untidy and poorly performing code. I wish to avoid this. I am also aware this can be achieved easily by modifying the source or destination schemas or by not using BizTalk. These routes are not open to me. Therefore this question is asking for examples showing a simple, elegant BizTalk solution to the problem. If you don’t wish to provide an answer please do not punish a person who desires to improve his knowledge and skills.


Solution

  • There is nothing wrong with your overall solution. There is one thing I would do differently.

    Yes, use a Script Functoid to convert the date, but instead of difference, just take the .Ticks Property of the DateTime as input to the Cumulative Minimum. This is returned as a Long. Then, you're not dependent on any date and the output is deterministic.

    Important, there is absolutely nothing wrong with using a Two Map solution. This is a perfectly acceptable Pattern in BizTalk Dev.

    You could probably do it in one Map, but that would require some inline Xslt Templates. There's also nothing wrong with that. But, a Two Map solution lets you use only built in Functoids.

    Don't worry about 'performance' unless you can prove you need to. The perf difference between one or two Maps will be barely measurable.