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.

2 comments:

Unknown said...

http://kentweare.blogspot.com/2008/10/biztalk-mapper-ensuring-that-node.html

Is there any way to check if the element does not exists so that i can map other element to the destination. Since IsExistence functoid does not return false how can i check for the existance of the element

Kent Weare said...

What about using the "Not" functoid that will return the opposite value of the IsExistence functoid inconjunction with the Value Mapping functoid?