October 14 2019

 

People working in Health care, Insurance, Transportation, Finance, Government, Supply chain, and many other industries may have already heard about EDI ASC X12 specification. This specification defines the data format standards that many of these industries follow when performing business to business (B2B) transactions. An organization can have many systems interacting over these formats, which makes it a common integration use case. Anypoint platform being an integration solution, a natural question that comes to mind is - How to do B2B integrations using MuleSoft’s Anypoint platform?

 

What is EDI X12?

Electronic Data Interchange (EDI) is an approach for business to business (B2B) communications over electronic mediums. This eliminates the need for paper communications and minimizes human interactions for completing business transmissions.

In 1979, the American National Standards Institute (ANSI) chartered the Accredited Standards Committee (ASC) X12 to develop and maintain uniform standards for inter-industry electronic exchange of business transactions - electronic data interchange (EDI).

 

 

What are EDI X12 Integrations?

As businesses communicate over EDI X12 formats, it is one of the crucial use cases for integration solutions. Organizations often require to receive X12 standard formats from their business partners and then send those to internal systems for processing.

Consider an example where XYZ Corporation would like to receive purchase invoices from ABC Supplier Inc. They can only send X12 Standard documents over SFTP to XYZ Corp.

 

For this use case, let’s assume that XYZ corporation uses Enterprise SAP and has an Invoice Processing API exposed to abstract SAP system. To enable X12 processing for ABC Supplier, the missing piece here is a solution that knows how to read and transform X12 standard formats into something that Invoice Processing API can understand.

 

MuleSoft X12 Module

MuleSoft provides many Modules (a.k.a. connectors) that help to connect with other systems or perform standard non-business related transformations. Fortunately, this collection of modules includes some EDI Modules such as X12, EDIFACT, AS2, etc.

We can use the X12 module to read the X12 Invoice documents received on SFTP and perform some business transformation on it. 

Our integration process would something like this - 

What is X12 Module?

X12 Module provides a mechanism to read, write, and validate EDI documents. It supports various versions of the X12 standard specification. It allows us to use our trading partner specific configurations and identifiers for reading and writing partner-specific documents.

In our case, we will use the read operation of the X12 module. This operation consumes EDI X12 data format and converts it into a standard java data model which then can easily be consumed by transformation components such as DataWeave. 

In Anypoint Studio, you can add this module to your project by searching it in Mule Palette. If needed, search in the exchange to download it. Once you add it to your project, you should see it in the palette - 

 

X12 Receiving flow

Once we have the X12 module added to our project, we can implement our flow to receive and parse the document. In a simplistic way, the flow would look like this - 

 

Logical operations happening in this flow - 

  1. Keep polling on SFTP server for any new files using SFTP Module

  2. Using X12 Module, read EDI file and convert to Java representation

  3. Convert EDI format into JSON model that our API can consume

  4. As there could be more than one invoices in an incoming file, send each of the converted JSON objects to remote 


Global Configurations:

    <sftp:config name="SFTP_Config" doc:name="SFTP Config" >
       <sftp:connection host="${sftp.host}" port="${sftp.port}" username="${sftp.username}" password="${sftp.password}" />
    </sftp:config>

    <http:request-config name="HTTP_Request_configuration" doc:name="HTTP Request configuration" basePath="/api" >
       <http:request-connection host="${api.invoice.host}" port="${api.invoice.port}" />
    </http:request-config>

 

X12 Module Global Configuration:

<!-- Configure X12 Module with trading partner configuration -->
    <x12:config name="X12_EDI_Config" doc:name="X12 EDI Config" 
       interchangeIdQualifierPartner="ZZ" interchangeIdPartner="SENDERISA" interchangeIdQualifierSelf="ZZ"
       interchangeIdSelf="RECEIVERISA" groupIdPartner="SENDERDEPT" groupIdSelf="RECEIVERDEPT">
       <x12:schemas >
           <x12:schema value="#['/x12/004010/810.esl']" />
       </x12:schemas>
    </x12:config>

 

Integration flow:

    <flow name="mule4-sftp-x12-demoFlow" >
       <sftp:listener doc:name="On New or Updated File" 
config-ref="SFTP_Config" directory="${sftp.pollingDirectory}">
           <scheduling-strategy >
               <fixed-frequency />
           </scheduling-strategy>
       </sftp:listener>
       <x12:read doc:name="Read" config-ref="X12_EDI_Config"/>
       <ee:transform doc:name="Transform Message" >
           <ee:message >
               <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload.TransactionSets.v004010."810" map {
    invoiceDate: $.Heading."020_BIG".BIG01 as Date as String  {format: "MM/dd/yyyy"},
    invoiceNummber: $.Heading."020_BIG".BIG02,
    orderNumber: $.Heading."020_BIG".BIG04,
    invoiceTotal: $.Summary."010_TDS".TDS01,
    currency: $.Heading."040_CUR02" default "USD",
    items: $.Detail."010_IT1_Loop" map (item, index) -> {
       description: item."060_PID_Loop"."060_PID".PID05[0],
       quantity: item."010_IT1".IT102,
       unit: item."010_IT1".IT103,
       price: item."010_IT1".IT104,
       IdCode: item."010_IT1".IT106,
       Id: item."010_IT1".IT107
   }
}]]></ee:set-payload>
           </ee:message>
       </ee:transform>
       <foreach doc:name="For Each" collection="#[payload]">
           <http:request method="POST" doc:name="Request" config-ref="HTTP_Request_configuration" path="/invoices" />
       </foreach>
    </flow>

 

With this flow in place, we will be able to read EDI files from SFTP folder, transform into Invoice JSON, and deliver it to our Invoice Processing API.

 

Where to go next?

This was just one standalone example of consuming EDI X12 transactions using the Anypoint platform. EDI is a vast landscape with more complicated use cases such as sending functional acknowledgments, accepting different types of documents, erroneous transaction processing, enabling a central EDI solution, etc. At AVIO, we look at these uses cases and can work on fitting them into your digital transformation journey. We evaluate how large scale B2B integrations can benefit from Anypoint Partner Manager to centralize your partner configurations. If this triggers any thought process or questions about your existing or upcoming B2B integrations, we can help you answer those, Just reach out to us.  

About the Author

Manik Magar

Manik Magar is a Technical Architect at AVIO Consulting. In his 12 year career, he has worked for many industries including Finance, Insurance, Retail, Investments etc. He is a MuleSoft Certified - Integration Architect (Level 1). He focuses on providing end to end solutions with mix of technologies. Manik is an active community member in MuleSoft Community. He is one of the first four official MuleSoft Ambassadors, which is a group of people who help MuleSoft developer community.    

Join the Conversation

Enter your first name. It will only be used to display with your comment.
Enter your email. This will be used to validate you as a real user but will NOT be displayed with the comment.