Inam Haq's EAI/BizTalk Blog...

Thursday, December 07, 2006

Merge Two fields with a newline in between using BizTalk map

Adding a newline and carriage return characters in a BizTalk map when merging two fields sounded very easy. There were two methods that came to my mind and that I could find on the web:
  • First option was to edit the map XSLT file and manualy add the characters to the map XSLT code. [To open map file for XSLT editing: right click on the map file and choose "Open with...". Then select "XML editor"]


  • Second option was to add a scripting functiod and link the input field from the source schema. Then add inline C# code to add the newline between the input fields and return the output string.
These two approaches work very fine. But I was looking for some easier (and a bit elegant) way out. So with a little effort I found out an easier way which I think is elegant too :).

The trick is to add a string concatenation functiod to the map grid. Then link the input fields from the source schema to this functiod. It is good idea to lable the links like address 1, address 2 etc; this will help (select the link and then add a friendly name to the "Lable" box in the properties window). Now select this functiod and choose "Configure Functiod Inputs" from the properties window. Click on the "Insert new parameter" button. A new parameter will appear as show in the diagram 1. Now select this newly added parameter and position it between the fields you want the newline character added.

Diagram 1


With the newly added parameter selected, click on the "Edit constant parameter" button.

Diagram 2

With the cursor in the new window that pops up, hit "Ctrl+Enter" (press the Enter key while holding down conrol key). Click OK and close the functiod inputs windows. Link the fuctiod output to the appropriate field in the destination schema.

That's it, you are all set now. The destination field with have the two inputs from the source message fields concatenated together with a newline character.

Labels: , ,