Testing for Empty/Nil/Missing Source Nodes in BizTalk Maps

Re-posted from another blog – original publish date 27 Aug 2012

Scenario: You are mapping an optional node in your source schema to an optional node in your target schema. But… the target schema has stricter validation rules and cannot accept empty or “nil” nodes, whereas the source schema can.

By default, if the source node doesn’t exist, it won’t be output in your target. No problems there. But… what if the source node is empty or null?

Let’s look at this mapping example:

BadMap

Here’s a source instance:

SchemaInstance

What will be output? You might be dismayed to find out it is this:

BadMapOutput

Both the nil and the empty source nodes output empty target nodes, which will be invalid for the target system. The only way to stop the empty nodes from being created is to map a “false” value from a logical functoid to the node. So if you’re a thorough programmer like myself, you might be tempted to do something like this:

MultipleTestFunctoidsExample

This will work great, covering every possible scenario for the NillableField1:

  • Field does not exist
  • Field is marked nil
  • Field is an empty string (e.g. size == 0).

But…six functoids!!  And that’s just for the one node mapping – you’d have to repeat this group for every other optional node, including the ZeroLengthField1 node.

Unless… one day you happen to discover these innocuous looking functoids sitting in the Logical section of your toolbox:

Toolbox2

Looking at the documentation for the “Logical String” functoid reveals this:

Use the Logical String functoid to return the value “true” if the input parameter is a string.

While not immediately obvious, the fact is that this single functoid performs the same tests that the entire group above does. If the source string node is either nil or empty, it returns false. As expected, the Logical Date and Logical Numeric functoids work in a similar way, respective to their particular data types.

So now your map can look like this:

IsStringFunctoidExample

… and still produce the desired output when using the instance above:

GoodOutput

I’ll be covering items like this in my first Pluralsight course, “Mapping in BizTalk 2013”, which I’m tirelessly working on at the moment (hence the reason for so few blog posts lately). It will hopefully be published before the end of this year.

UPDATE: The Pluralsight course is now live and can be accessed here!

About Dan Toomey
Husband, father, Enterprise integration geek, Microsoft Azure MVP, Pluralsight author, Brisbane Azure User Group leader (@BrisbaneAzureUG), MCPD, MCT, MCTS & former professional musician.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

John Glisson - Geek of the Cloth

Thoughts on integration, technology and what-not...

prashantbiztalkblogs

My BizTalk Experiences

The CRUCIBLE

THINK: It's not illegal....yet.....

paulbouwer.com

life and technology

Abdul Rafay's BizTalk Blog

My experiences with BizTalk related to architecture, development and performance in my enterprise.

Mike Diiorio

Connected Systems and other thoughts

BizTalk musings

Issues, patterns and useful tips for BizTalk development

EAI Guy.net

Enterprise Applicaiton Integration and SOA 2.0

Connected Pawns

Mainly BizTalk & Little Chess

Man Vs. Machine

Why can't we all just get along?

Adventures inside the Message Box

BizTalk, Azure, and other tools in the Microsoft stack - Johann Cooper

Biz(Talk)2

Talk, talk and more talk about BizTalk

Richard Seroter's Architecture Musings

Blog Featuring Code, Thoughts, and Experiences with Software and Services

Sandro Pereira BizTalk Blog

My notes about BizTalk Server 2004, 2006, 2006 R2, 2009, 2010, 2013 and now also Windows Azure BizTalk Services.

BizTalk Events

Calendar of BizTalk events all over the world!

Mind Over Messaging

Musings on BizTalk, Azure, WCF, and Enterprise Integration

The WordPress.com Blog

The latest news on WordPress.com and the WordPress community.

%d bloggers like this: