Jul 262007

Warning, the following code is not pretty!  Often times I get into a situation where I lose my confidence in the finesse of the Biztalk Mapper.  That’s when I pull out my sledge hammer.  This is one of those occasions.

The following map wouldn ‘t work when the ST qualified or ship-to information  was not in the 1st N1 loop.  The output would always be blank.  I tried fruitlessly using every combination of looping functoid, value mapping functoid, and value mapping flattening functoid to no avail.


To make it work with functoids I created two “Functoid Array Strings”.  The first string (IterationString_1 in the VB.Net Scripting Functoid parameter) contains the Looping Iteration followed by a “*” followed by the N1 qualifier I was searching for.  Essentially my Iteration string would look like this – 1*CR2*IT3*ST4*IM.  I bolded the ST to show that it is found in the 3rd iteration of the loop.  Once i knew I was looking for Iteration 3 of the loop I could take in element I was looking for in the same “Iteration*Element” string format I created earlier.  As soon as I found the 3rd iteration i can just pull out the element I need and never have to worry about looping, I get the value every time.


Here’s the functiod logic.

Public Function ReturnSTInfo_1(ByVal IterationSTring_1 As String, ByVal N104_1 As String) As String Dim BeginningIndexValue_1 As Integer Dim EndingIndexValue_1 As Integer Dim LengthOfElement_1 As Integer BeginningIndexValue_1 = System.Convert.ToInt32(IterationSTring_1.Substring((IterationSTring_1.IndexOf("ST") - 2), 1)) EndingIndexValue_1 = BeginningIndexValue_1 + 1 If N104_1.IndexOf(System.Convert.ToString(EndingIndexValue_1) + "*") = -1 Then Return N104_1.Substring((N104_1.IndexOf(System.Convert.ToString(BeginningIndexValue_1) + "*") + 2)) Else LengthOfElement_1 = (N104_1.IndexOf(System.Convert.ToString(EndingIndexValue_1) + "*")) - (N104_1.IndexOf(System.Convert.ToString(BeginningIndexValue_1) + "*") + 2) Return N104_1.Substring((N104_1.IndexOf(System.Convert.ToString(BeginningIndexValue_1) + "*") + 2), LengthOfElement_1) End If End Function