Monday, February 26, 2018

Logic Apps: Decode X12 messages and transform them with Liquid

In this post, I will explain how to validate and decode X12 messages (EDI 850 401 in this example) and transform the content with Liquid Maps.

First step is create our Integration Account and add there our X12 schema. In this example, I will use EDI 850 401 schema that can be download here, a link from the Public repository for Microsoft Integration open source samples, code and tools.


Second step is create our partners in our Integration Account.


Hostpartner:
  • Type: B2B
  • Qualifier: 1 - D-U-N-S (Dun & Bradstreet)
  • Value: 123456789P
Guestpartner:
  • Type: B2B
  • Qualifier: 12 - Telephone Number
  • Value: 2052479010
Third step is create the Agreement between Partners in our Integration Account:


Now I will develope a simple Logic App, that:
  1. Triggers with "When one or more blobs are added or modified"
  2. Get the content of the blob with "Get Blob Content"
  3. Resolve the Agreement with "Resolve X12 Agreement"
  4. Decode the blob content with "Decode X12 message"

Now I will add a for each statement, to get all the valid decoded messages:


This allows a loop for each valid decoded message from my original X12 file.

Now let's go to modify these good messages with Liquid maps. I need to convert each good message to JSON, with this expression:
json(xml(base64ToBinary(items('For_each')?['Payload'])))

This expression will generate a JSON with a similar structure and names that the X12 XML:

{
  "content": {
    "ns0:X12_00401_850": {
      "@xmlns:ns0""http://schemas.microsoft.com/BizTalk/EDI/X12/2006",
      "ST": {
        "ST01""850",
        "ST02""476810004"
      },
      "ns0:BEG": {
        "BEG01""00",
        "BEG02""SA",
        "BEG03""69114620",
        "BEG05""20071101"
      },
      "ns0:CUR": {
        "CUR01""BY",
        "CUR02""USD"
      },
      "ns0:REF": [
        {
          "REF01""VR",
          "REF02""TRI"
        },

My Liquid map will be very simple, only to demostrate how to get values from this JSON:

Now save this map to a file and add to your Integration Account:


Use this map on your Logic App with "Transform JSON to JSON":


This is the output that we get with our Liquid map:





2 comments:

  1. How to create a liquid template for any EDI file?

    ReplyDelete
  2. I'm trying to convert 837P EDI file to JSON. I'm following the above steps and stuck in liquid map.

    ReplyDelete