Recently there’s a requirement to eliminate the duplicate records in the output using BizTalk map.
Brilliant solution can be found here:
I’ve added step by step on how to do it.
Overall solution it looks like this:
You’ll need 2 script functiods and Equal logical functoid
- Top functoid will contain the declaration of variable with following code:
System.Collections.Specialized.StringCollection uniqueIds = new System.Collections.Specialized.StringCollection() ;
2. Another functoid will take in the ID of source messsage wherein the uniqueness will be checked. In this case, CustomerId as input. The following code is as follows:
public bool IsUniqueId(string id)
{
if (uniqueIds.Contains(id))
return false;
uniqueIds.Add(id);
return true;
}
3. Equal logical functoid will take the output of the second script functoid and output should be map to the target record
This is my input message:
<ns0:MasterData xmlns:ns0=”http://BizTalk_Server_Project1.Order”>
<Customer>
<CustomerId>1</CustomerId>
<CustomerName>Customer 1</CustomerName>
</Customer>
<Customer>
<CustomerId>1</CustomerId>
<CustomerName>Deplicate Customer</CustomerName>
</Customer>
<Customer>
<CustomerId>2</CustomerId>
<CustomerName>Customer 2</CustomerName>
</Customer>
</ns0:MasterData>
And this is the output:
<?xml version=”1.0″?>
<ns0:MasterData xmlns:ns0=”http://BizTalk_Server_Project1.Order”>
<Customer><CustomerId>1</CustomerId>
<CustomerName>Customer 1</CustomerName></Customer>
-<Customer>
<CustomerId>2</CustomerId>
<CustomerName>Customer 2</CustomerName>
</Customer>
</ns0:MasterData>
Viola!!, without using xslt you can achieve same results.