BizTalk Server Tutorial

BizTalk Server Concepts and Common Errors

Useful Cheat Code in Mapping (Storing a Repeating Record in an Array)

This is another useful cheat code which will be very helpful in EDI mapping.
This post will help you how to store a value in a Repeating Record into an Array.

Problem:

Image, you have an Employees schema, and input message which has multiple Employee Records:


From the above input message, assume you should get the Employee message who is taking the highest Salary. For example: from the above sample message, I want to map 3rd record (taking the highest salary of 9000) from source to target.

Solutions:

1. Many people generally go with XSLT.

 (or)

2. Loop through the Input message, find the highest salary. Map only that employee having the highest Salary.

How to achieve Option#2 ?

1. Connect the Salary to a Concatenation Functoid and give a delimiter character which doesn’t occur in the input message.

2. Connect the output of the Concatenation Functoid to a Cumulative Concatenate Functoid

3. Now if you see the output of the above two Functoid, we get the below string:

5000~3000~9000~1000~

This is the salary of each Employee record, separated by a delimiting character.

4. Apply C# script to

a. Split the above string into an Array
b. Sort the Array
c. Find the highest Salary.

Connect the output of the above two Functoids to a Scripting Functoid and Use a small script to execute the steps a,b,c.

5. The output of the above script will give you a value of 9000, which is the highest salary in the input schema.
6. Now use Logical Equal Functoid to connect the output of the above script and Salary element of Input Schema and Connect to the Employee Record of Target Schema.

7. Now connect each element in Source to Target.

8. Now if you test the above map with the input message (at the top of this post), you get only one Employee in the output whose Salary is the highest.

Note:

1. This has a limitation that the delimiting character used in Step1 should not occur in the Input element. Else, C# script will wrongly interpret the data.

2. In Such a case you can use my other Cheat Code and Loop thorugh each repeating record using XSLT and add those items into an array.

– Shiv

April 23, 2012 - Posted by | Maps | , , , ,

2 Comments »

  1. Very nice trick..Just helped my issue..Thanks a lot..

    Comment by Saran | May 9, 2016 | Reply

  2. Great Post .. Will Be Very Helpful…

    Comment by sadanand | April 22, 2015 | Reply


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

%d bloggers like this: