26 June 2008

Value Mapping (Flattening) Functoid Troubles

A while ago I was troubleshooting a BizTalk solution my company created. This solution facilitates the communication between a CRM front-end and a commonly used municipal back-office system. I had not created this app, so it took me a while to figure out what the problem was. The trouble was that something went wrong in one of the maps. Some messages that went through the map were correctly processed, while others weren’t. Here’s the map (click to enlarge):



The map's functionality

The map transforms a response of the back-office to a message format the CRM system understands. It’s quite straightforward; the input schema contains a root element that in turn contains one choice element. The options for the choice element are three (although one of them isn’t used, don’t ask me why) tree structures that are the same, except for their names. Scripting functoids are used to concatenate some fields (and do some other stuff) from the input message and the result is fed to Value Mapping (Flattening) functoids. These functoids have two input parameters: the first is the result of a Logical Existence functoid that checks the existence of one of the choice elements, the second contains the concatenated values of some fields. The result of the Value Mapping (Flattening) functoid is the second parameter if the first one is true. So to summarize, the map checks the existence of the choice element options and when the element exists maps the concatenated values of some fields in this element to the output message.

Problem

The weird thing was, that only messages with the BinnenVerhuisaanvraagResponse element (excuse my dutch) were mapped correctly. When a message contained an UittrekselaanraagResponse element, the output message missed the mapped fields (should be in the InputData field of the output message). This was very strange, because the messages were identical, except for the names of the choice element options. Also I double-checked the functoids, but they were again the same.

The Value Mapping (Flattening) functoid

What had caught my attention briefly earlier was the use of the flattening version of the Value Mapping functoid. This version flattens a tree structure input to a single field. The input of these functoids in this map however is always a single value from a Scripting functoid. Maybe the reason was that in an earlier version the Scripting functoids weren’t used, but the input fields directly, but that’s just a wild guess. Anyway, in this case there is no need for the flattening version of the Value Mapping functoid. So I replaced these with the normal Value Mapping functoids, ran some tests and hey, all messages are processed just fine?! I could not find anything on the net as to why this happened, I might have stumbled on a bug here, although I have not tested this error in other environments. So, be aware of this when using the Value Mapping (Flattening) functoid in source schemas containing choice elements!