Saturday 12 September 2015

How to avoid generation of empty nodes in BizTalk Mapper using Logical Existence functiod


Problem:
 In a company there was a requirement to send various messages to consume a web service.

I am using BizTalk 2013 R2 to consume the Web Service that have 3 ELEMENT/node that can have more than 1 Records i.e. ‘Min Occurs’=0 and ‘Max Occurs’=Unbound. But in source schema we can have any record not present (no data) under any of 3 ELEMENT/node in this case do not send that ELEMENT/node’, even if we send any ELEMENT/node as Empty tag like “<HeaderResultError/> web service 100% do not receive that empty node and replies invalid data:

Solution:
When I was simply mapping the node/Elements using “Copy text value” in BizTalk mapper when there is no data\empty in Source schema BizTalk mapper was sending empty node in destination schema and as a result creates Empty tag like “<HeaderResultError/>”, but this is not accepted by WebService.

I use “Logical Existence” functoid as it has characteristic to check if any attribute, field element and even record exists in source schema then generate the schema node under destination schema.
“Logical Existence” description is “Use the Logical Existence functoid to return the value "true" if the input record or field exists in the source message. This functoid requires one input parameter only.”

So if we have any value in source schema “Logical Existence” returns true then schema node will be generated in destination schema, and if there is no value under source schema Logical Existence will not generate empty node in destination schema:
Steps To use Logical Existence in BizTalk Mapper:

1)    Drag a Logical Existence

2)    Connect the attribute\element from Source schema to Logical Existence functoid.

3)    Connect the Logical Existence to Value Mapping Functoid.

4)    Connect attribute\element from Source schema to Value Mapping (If there is value/data in attribute\element of Source schema, it will pass the actual value to destination schema)

5)    Connect Value Mapping to the attribute\element in destination schema.
 
Finally we will have mapper look like: