Wednesday, August 11, 2010

Extract the iteration from a repeating loop designated by a certain qualifier.

A while back I posted a solution that helped me extract the value from a repeating loop designated by a qualifier.  I've seen this come up many times with EDI, either you're extracting a ST or ship-to information or a REF reference information.  Although my previous solution worked it involved adding 4 functiods and changing data within the scripting functiod depending on the Qualifier.  I've simplified it to only require 3 functoids and no need for adjusting the script inside of the functoid. 


Here's an example of what your 3 functoids would look like.




1.  Add a "^" before and after the Qualifier



2.  The scope of the Cumulative Concatenate Functoid should be 1.


3.  The Scripting Functoid Input will be the Qualifier you're wanting to find and the output from the Cumulative Concatenate functoid.


4.  Finally Insert the following code into the Scripting Functoid (Inline Visual Basic .NET)



Public Function RepeatingLoopWithQualifier_1(ByVal Qualifier As String, ByVal All_Qualifiers_and_Values_Concatonated As String) As String
'All_Qualifiers_and_Values_Concatonated Expects a Commulative Concatonated String of all
'Qualifers preceded by a "^" and Values preceded by a "^" for example ^ST^912 Summer DR.^BT^4312 W. Powell
Dim QualifierLocation As Integer = All_Qualifiers_and_Values_Concatonated.IndexOf("^" + Qualifier + "^")
Dim QualifierandValueSplit As String()
'If Qualifier is found, find the corresponding Value, else Return ""
If QualifierLocation >= 0 Then
QualifierandValueSplit = All_Qualifiers_and_Values_Concatonated.Substring(QualifierLocation + 1, All_Qualifiers_and_Values_Concatonated.Length - (QualifierLocation + 1)).Split("^")
Return QualifierandValueSplit(1)
Else Return ""
End If
End Function

C#


public string RepeatingLoopWithQualifier_1(string str_Qualifier, string str_AllQualifiers_and_Values_Concatonated)
 {
string[] _ary = str_AllQualifiers_and_Values_Concatonated.Split(new char[] {'^'});
string result = "";
if (str_AllQualifiers_and_Values_Concatonated.IndexOf("^" + str_Qualifier.Trim() + "^")>-1)
for (int i=0; i< _ary.Length; i++)
{ if (_ary[i] == str_Qualifier.Trim()) result = _ary[i+1]; }
return result;
}