Access EDI ISA/GS Header Fields In a BizTalk Orchestration

How can you get values from the ISA/GS into variables in your BizTalk Orchestration?

Link to a good easy to read summary of ISA/GS segments in EDI:

I have included screen shots of their PDF here:

To get the Intellisense and compile/build to work, you will have to add a reference to Microsoft.BizTalk.Edi.BaseArtifacts.dll.

// define the variables that start with "str" and "char".
// msg204In in the message name that was in a prior receive shape. 
strISASegment = msg204In(EDI.ISA_Segment);
strGSSegment = msg204In(EDI.GS_Segment);

// position 103 always contains the field separator, 
// ISA Segment is fixed Length 
charEDIFieldSeparator = System.Convert.ToChar(strISASegment.Substring(103,1)); 

strISA13 = CSharp.Helpers.EDI.getEDIFieldFromSegment
      (strISASegment, charEDIFieldSeparator, 13); 
strGS06  = CSharp.Helpers.EDI.getEDIFieldFromSegment
      (strGSSegment,  charEDIFieldSeparator, 06); 

EDI.ISA_Segment and EDI.GS_Segment return the entire segment as a string. You will probably need a C# helper class to split based on the delimiter, as shown in the next code sample below.

The ISA Segment is fixed length and ends with three delimiter characters, for example: *:~.
That means the asterisk is the delimiter for fields, tilda is the delimiter for lines, and the colon is the delimiter for components or sub-elements (less frequently used). So you can get the field separator by doing a substring on character in the 104th position (103 if zero based).

public static class EDI
        public static string getEDIFieldFromSegment(string stringToSplit, char separator, int positionToReturn)
            string[] resultString;
            resultString = stringToSplit.Split(separator);
            if (resultString.Length >= positionToReturn)
                return resultString[positionToReturn];
                return "getEDIFieldFromSegment:Error: Position Requested ${positionToReturn} greater than number of items ${resultString.length}";


NOTE: The above technique works with any and all ISA/GS fields. shows all the EDI fields available.

In other words, for these fields, you can do the following:

strGS06 = msg204In(EDI.GS06);

I found this related blog after I wrote the above:… But I’ve found that old blogs on Microsoft sites can often disappear and links don’t work after a few years. That blog also shows how to use the ISA/GS fields in a map by loading them into an XMLDocument.

Related Related MSDN forum discussion

The “ContextAccessor” is a third party tool that is also available to access these fields from maps, but it works differently. It uses a functoid to access the context fields, and has the ability to get each individual field. It was hosted on CodePlex, but I need to research where it’s new home resides.


Leave a Reply