Logic Apps error "structural error in/before the first functional group"

448 Views Asked by At

I am reading an X12 850 from an Azure Queue and seek to get the XML representation of it, decoded by Logic Apps. Here is the sample EDI doc that I am using:

ISA*00*          *00*          *12*TEST123ZZZ     *12*ZZZ123TEST     *171010*0705*U*00401*000032485*0*P*>~
GS*PO*TEST123ZZZ*ZZZ123TEST*20171010*070547*32485*X*004010~
ST*850*32485~
BEG*00*SA*Z-5000**20171010~
REF*PG*LLL~
DTM*002*20171113~
N1*ST*SUPERLATIVE AUTO PARTS INC.*92*4500~
N3*5555 33 MILE RD.~
N4*ARMADA*MI*48005~
PO1*1*10*EA*2.27**BP*P2224*VP*L033~
PO1*2*10*EA*5.53**BP*P5544*VP*L059~
PO1*3*10*EA*4.11**BP*P1237*VP*L020~
PO1*4*20*EA*16.3**BP*P0999*VP*L006~
CTT*4*50~
SE*13*32485~
GE*1*32485~
IEA*1*000032485~

Out of Decode, I am getting nothing in goodMessages, instead all in badMessages. It looks to me like my Agreement is being picked up and used (the only Agreement I have set up), but I am at a loss at how to respond to the exception "The interchange with id 000032485, with sender id 'TEST123ZZZ ', receiver id 'ZZZ123TEST ' had structural error in/before the first functional group"

"body": {
    "interchangeControlNumber": "000032485",
    "groupControlNumbers": [],
    "goodMessages": [],
    "badMessages": [
        {
            "interchangeEnvelope": {
                "ISA_Segment": "ISA*00*          *00*          *12*TEST123ZZZ     *12*ZZZ123TEST     *171010*0705*U*00401*000032485*0*P*>~\r\n",
                "isA05": "12",
                "isA06": "TEST123ZZZ     ",
                "isA07": "12",
                "isA08": "ZZZ123TEST     ",
                "isA09": "171010",
                "isA10": "0705",
                "isA11": "U",
                "isA12": "00401",
                "isA13": "000032485",
                "isA14": "0",
                "isA15": "P"
            },
            "technicalAckExpected": false,
            "functionalAckExpected": false,
            "exception": "The interchange with id '000032485', with sender id TEST123ZZZ      , receiver id ZZZ123TEST       had structural error in/before the first functional group",
            "componentSeparator": 62,
            "dataElementSeparator": 42,
            "interchangeControlNumber": "000032485",
            "payload": "77u/R1MgKiBQTyAqIFRFU1QxMjNaWlogKiBaWloxMjNURVNUICogMjAxNzEwMTAgKiAwNzA1NDcgKiAzMjQ4NSAqIFggKiAwMDQwMTB+DQpTVCAqIDg1MCAqIDMyNDg1fg0KQkVHICogMDAgKiBTQSAqIFogLSA1MDAwICogKjIwMTcxMDEwfg0KUkVGICogUEcgKiBMTEx+DQpEVE0gKiAwMDIgKiAyMDE3MTExM34NCk4xICogU1QgKiBTVVBFUkxBVElWRSBBVVRPIFBBUlRTIElOQy4qIDkyICogNDUwMH4NCk4zICogNTU1NSAzMyBNSUxFIFJELn4NCk40ICogQVJNQURBICogTUkgKiA0ODAwNX4NClBPMSAqIDEgKiAxMCAqIEVBICogMi4yNyAqICpCUCAqIFAyMjI0ICogVlAgKiBMMDMzfg0KUE8xICogMiAqIDEwICogRUEgKiA1LjUzICogKkJQICogUDU1NDQgKiBWUCAqIEwwNTl+DQpQTzEgKiAzICogMTAgKiBFQSAqIDQuMTEgKiAqQlAgKiBQMTIzNyAqIFZQICogTDAyMH4NClBPMSAqIDQgKiAyMCAqIEVBICogMTYuMyAqICpCUCAqIFAwOTk5ICogVlAgKiBMMDA2fg0KQ1RUICogNCAqIDUwfg0KU0UgKiAxMyAqIDMyNDg1fg0KR0UgKiAxICogMzI0ODV+DQpJRUEgKiAxICogMDAwMDMyNDg1fg==",
            "replacementCharacter": 0,
            "segmentTerminator": 126,
            "segmentTerminatorSuffix": "CRLF",
            "agreementName": "X12-TEST123ZZZ-ZZZ123TEST",
            "guestPartnerName": "Test-Partner",
            "hostPartnerName": "Plex-As-Host",
            "ReceiverIdentifier": "ZZZ123TEST",
            "receiverQualifier": "12",
            "SenderIdentifier": "TEST123ZZZ",
            "senderQualifier": "12"
        }
    ],
    "generatedAcks": [],
    "receivedAcks": [],
    "agreementName": "X12-TEST123ZZZ-ZZZ123TEST",
    "guestPartnerName": "Test-Partner",
    "hostPartnerName": "Plex-As-Host",
    "ReceiverIdentifier": "ZZZ123TEST",
    "receiverQualifier": "12",
    "SenderIdentifier": "TEST123ZZZ",
    "senderQualifier": "12"
}

}

I am getting told by my EDI colleagues that "ISA02 should be 10 spaces The total length of the ISA segment should be 106 characters" So, I am thinking I don't have the Agreement configured correctly for ISA2. Should I be putting something in the ISA2 field in the Agreement? I tried ten spaces, which it took, but I still get the same error: "The interchange with id 000032485, with sender id TEST123ZZZ, receiver id ZZZ123TEST had structural error in/before the first functional group"

Agreement UI

3

There are 3 best solutions below

4
On

You ISA Segment looks fine, structurally. ISA02/04 are most often left blank.

But looking at the other content, is there a space after all the ~'s? That would cause problems. Only CR and/or LF are allowed as suffex's.

1
On

It seems some EDI validators have problems with dealing with the PO1 loop having no children elements.

The following message passes validation, by having MSG segments as child to PO1:

ISA*00*          *00*          *12*TEST123ZZZ     *12*ZZZ123TEST     *171010*0705*U*00401*000032485*0*P*>~
GS*PO*TEST123ZZZ*ZZZ123TEST*20171010*070547*32485*X*004010~
ST*850*32485~
BEG*00*SA*Z-5000**20171010~
REF*PG*LLL~
DTM*002*20171113~
N1*ST*SUPERLATIVE AUTO PARTS INC.*92*4500~
N3*5555 33 MILE RD.~
N4*ARMADA*MI*48005~
PO1*1*10*EA*2.27**BP*P2224*VP*L033~
MSG*LINE ITEM 1~
PO1*2*10*EA*5.53**BP*P5544*VP*L059~
MSG*LINE ITEM 2~
PO1*3*10*EA*4.11**BP*P1237*VP*L020~
MSG*LINE ITEM 3~
PO1*4*20*EA*16.3**BP*P0999*VP*L006~
MSG*LINE ITEM 4~
CTT*4*50~
SE*17*32485~
GE*1*32485~
IEA*1*000032485~

I tested this using an online EDI validator: http://edivalidation.com/valid.html

0
On

I actually had two issues I had to solve. Both had to do with the console app I wrote to send a message into the Azure Queue read by the Logic App. Pasting the EDI document in as the value to a string variable ended up seeing spacing injected around the asterisks. That was the first problem. Seconding, putting the BrokeredMessage into the queue, I had to use an explicit MemoryStream to make certain the content was altered in no way (extra characters were being added), as explained here http://www.bfcamara.com/post/84113031238/send-a-message-to-an-azure-service-bus-queue-with

Once I corrected both issues (and configured my Integration Account to retain interchange details on decoding) I successfully saw the X12 decoded into XML by Logic Apps.