This project has moved. For the latest updates, please go here.

Issue with EDI format export

Jan 22, 2014 at 1:26 AM
I am working with the EdiFabric.Definitions.X12_004010_846 document and attempting to create EDI txt files.

The vendor is providing S_LDT_2 data, but the data structure is not generating the correct format. Here is the result in EDI-TXT:

LDT~

Here is the XML (inside the G_QTY node):
                <S_LDT_2>
                  <S_LDT_2>
                    <D_345_1>AE</D_345_1>
                    <D_380_2>7500</D_380_2>
                    <D_344_3>DA</D_344_3>
                  </S_LDT_2>
                </S_LDT_2>
My C# code to write this element is:
    public S_LDT_2 AddLeadtimeToQtyGroup(G_QTY qty, string leadCode, Int32 inventoryAmt, string timeCode = "DA")
    {
        S_LDT_2 leadtime = new S_LDT_2();

        qty.S_LDT_2.Add(leadtime);
        leadtime.D_345_1 = leadCode.Fit(2, 2);
        leadtime.D_380_2 = inventoryAmt.ToString();
        leadtime.D_344_3 = timeCode.Fit(2, 2);

        return leadtime;
    }
(NOTE: the Fit() is just a String extension to force the contents between min and max size).

As far as I can tell, my code is correct and the XML is as expected, but the EDI is broken.
Feb 12, 2014 at 7:52 PM
I have a fix that resolves this issue:

Edit the framework > Helpers > ParserHelper and replace the function with this code:
public static List<string> ParseSegment(XElement segment, ParseTree parseTree, InterchangeContext interchangeContext)
        {
            var result = new List<string>();

            if (segment.Name.LocalName.StartsWith("G_"))
            {
                foreach (var childSegment in segment.Elements())
                {
                    var segmentGrammar =
                        GetParsingGrammarForSegment(
                            new ParseTree
                                {
                                    TypeName = parseTree.TypeName.Replace(parseTree.Name, childSegment.Name.LocalName),
                                    AssemblyName = parseTree.AssemblyName
                                });
                    result.AddRange(ParseSegment(childSegment, segmentGrammar, interchangeContext));
                }

                return result;
            }

            if (segment.Name.LocalName.StartsWith("S_"))
            {
                // fix for segment loops (loop of segments of same type)
                var firstChild = segment.Elements().FirstOrDefault();

                if (firstChild != null && firstChild.Name.LocalName.StartsWith("S_"))
                {
                    foreach (var childSegment in segment.Elements())
                    {
                        result.Add(ParseDataElements(childSegment, parseTree, interchangeContext));
                    }
                }
                else
                {
                    result.Add(ParseDataElements(segment, parseTree, interchangeContext));
                }

                return result;
            }

            throw new ParserException("Can't parse segment " + segment.Name);
        }
Marked as answer by pmobley on 2/12/2014 at 11:53 AM
Coordinator
Feb 12, 2014 at 11:21 PM
As discussed in another thread:

it's a bug in the definition files and how they get deserialized. Decorate all segment lists like this:

[XmlElement("S_DTM")]
public List<S_DTM> S_DTM {
Feb 14, 2014 at 9:29 PM
I assume you mean to modify the definition files, right?
Coordinator
Feb 16, 2014 at 10:56 PM
Correct
Coordinator
Feb 17, 2014 at 10:21 AM
I haven't had the time to test the fix you made, but if looks like a better than modifying all definitions. Thanks for that, will include it in the next release (already got enough fixes\issues).
Coordinator
Apr 30, 2014 at 9:07 AM
This has now been resolved in Release 2.0