Showing posts with label BizTalk Mapper. Show all posts
Showing posts with label BizTalk Mapper. Show all posts

Friday, February 26, 2010

BizTalk 2009: BizTalk Mapper - get value from last node

I ran into a situation where I needed to get the last value from a re-occurring node that SAP was returning.


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.

Sunday, October 5, 2008

BizTalk Mapper: Ensuring that Node Exists before calling scripting Functoid

A scenario that I have recently encountered is that I have an optional element coming in that, if present, requires some manipulation before it can be assigned on the outbound message. The problem that I encountered is that an exception is raised when the map is executed and has nothing to pass to the 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. The issue is that if the element doesn't exists, then BizTalk will generate the following exception(truncated for readability):
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:

  1. An boolean indicator that if True will output the 2nd input
  2. The 2nd input will be passed to the next functoid(or element) should the 1st input be true.
Without the scripting functoid, BizTalk takes care dealing when elements exist and when they do not. The addition of the scripting functoid creates some issues when the Optional element is not provided in the message. But, with a couple standard functoids, a check can be made that only calls the scripting functoid when the element is provided.

Sunday, August 24, 2008

BizTalk Mapper: Transforming Comma Delimited List into Elements

Recently, I had a requirement in one of my projects to break apart a list of items inside of one element. Each item was separated by a comma and would need to be placed into its own element. For instance within an element I may have a list of employees with each one separated by a comma: 9123456,9123455,9123444,9123456

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:

  1. The list of Employees( or Vehicles)

  2. 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>