In order to extract the last record, I utilized the Record Count functoid and fed that value into the Index functoid. The Index functoid is also fed with the value from the "WA" element that I am really interested in. The result is then passed to a String Concatenate functoid where the data is enriched before being assigned to the destination document.
I have created this blog to document some of the techniques/patterns/tricks that I have come across during some of my projects.
Friday, February 26, 2010
BizTalk 2009: BizTalk Mapper - get value from last node
Sunday, October 5, 2008
BizTalk Mapper: Ensuring that Node Exists before calling scripting Functoid
Below is an image of my original map. All elements are required except Operation. The Operation element is of type long and a third party system will be sending this so we don't have total control over the data types. The equivalent element on the destination message is VORNR which happens to be part of an SAP IDoc. The element on the IDoc is also optional, but if it is provided, it needs to have padded values to make it a 4 digit string. So if 220 is provided by the source system then 0220 needs to be passed to the IDoc.
Below is an image of a message sent in without the Operation element.
Exception type: OverflowExceptionSource: mscorlibTarget Site: Int64 System.IConvertible.ToInt64(System.IFormatProvider)The following is a stack trace that identifies the location where the exception occurred
So to get around this, I have added some checks in the Map to ensure that the scripting functoid is only called when the Operation element exists.
The checks come in the form of Logical Existence and Value Mapping functoids. The Logical Existence functoid will return "True" or "False" based upon whether or not the element/attribute that you connect it to exists. You then use this output to feed the Value Mapping functoid. The Value Mapping functoid requires two inputs:
- An boolean indicator that if True will output the 2nd input
- The 2nd input will be passed to the next functoid(or element) should the 1st input be true.
Sunday, August 24, 2008
BizTalk Mapper: Transforming Comma Delimited List into Elements
So after looking around the net to see if someone else has had to deal with this challenge, a colleague forwarded on this link to me by Michael J. Williams. The context of this link was pure XSLT with nothing BizTalk related in it.
So I figured that I would create a post that would show you how you can do something similiar, but how you would accomplish this inside of BizTalk.
So to further illustrate what my inbound message looks like, here is an example:
For both VEHICLE_LIST and EMPLOYEE_LIST I am expecting a list of values separated by commas within one element.
However, the destination system is expecting them in their own element as shown below:
So inorder to solve this problem I am going to use a standard BizTalk Map and use the scripting functoid.
Within the Scripting Functoid I am going to call an "Inline XSLT Template".
The XSLT requires two parameters:
- The list of Employees( or Vehicles)
- A delimiter character - in my example I am using a comma ','
Here is the code listing that I have used and is based upon Michael's post. I have made a few modifications including:
- Removing his inititial template. In his example he had one template calling another. In my example, it is the scripting functoid that is initating the XSLT call and the parameters come from the Functoid input parameters.
- Included the
tags to reflect my requirements. - Provide a check to deal with a comma being included in the list but no value is included.
<xsl:template name="output-Employees">
<xsl:param name="list" />
<xsl:param name="delimiter" />
<xsl:variable name="newlist">
<xsl:choose>
<xsl:when test="contains($list, $delimiter)">
<xsl:value-of select="normalize-space($list)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(normalize-space($list), $delimiter)" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="first" select="substring-before($newlist, $delimiter)" />
<xsl:variable name="remaining" select="substring-after($newlist, $delimiter)" />
<xsl:if test ="string-length($first) != 0">
<EmployeeID>
<xsl:value-of select="$first" />
</EmployeeID>
</xsl:if>
<xsl:if test="$remaining">
<xsl:call-template name="output-Employees">
<xsl:with-param name="list" select="$remaining" />
<xsl:with-param name="delimiter">
<xsl:value-of select="$delimiter" />
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>