Create a Map For Inbound EDIFACT to JSON or XML

Use the MuleSoft template named Template to create inbound and outbound EDIFACT message transformation to help you map EDI EDIFACT transactions to an application message format, such as JSON or XML.

This template uses DataWeave in Anypoint Studio to create the mapping between the inbound EDIFACT transactions and the application format. It uses the application JSON or XML schema as input for the mapping.

To use the template to create the mapping:

  1. Create a project in Studio based on the template.

  2. Set the source EDIFACT message type.

  3. Set the Target JSON or XML Message Type

  4. Test the map locally.

Create a Project From a Template

Create a template project in Anypoint Studio:

  1. Launch Anypoint Studio.

  2. From the File menu, select New > Project from Template.

  3. Log in to Anypoint Exchange with your Anypoint Platform credentials.

  4. Search for edifact.

  5. Click Template to create inbound and outbound EDIFACT message.

  6. Do either of the following:

    • Click Open, to create a new project in your Studio workspace that preloads the template.

    • Download the template from Exchange and open the Mule configuration file 01-inbound-edifact-transform.xml in the downloaded template.

Set the Source EDIFACT Message Type

The 01-inbound-edifact-transform.xml template is configured with the EDIFACT version D97A, ORDERS message type. Follow these steps if you need to change the message type:

  1. From the Studio Package Explorer, select 00-global-configs.xml in the b2b-edifact-transform-template.

  2. In the Studio canvas, click the Global Elements tab.

  3. Select EDIFACT_Read and click Edit.

  4. In the Value field, select /edifact/d97a/ORDERS.esl and click the edit icon.

  5. Change the schema value to the version and transaction set you want to map from.

    For example, set Value to /edifact/d96a/INVOIC.esl, to map from the D96A Invoice message.

  6. Click Finish.

Set the Target XML or JSON Message Type

Set the target message type to transform inbound EDIFACT messages to your application’s message format:

  1. Copy the schema file of your target application message type into the <Project-name>/src/main/resources folder in Package Explorer.

  2. Select the 01-inbound-edifact-transform.xml flow.

  3. From the Message Flow tab in the Mule Palette view, select the Transform Message component.

  4. In the Output section, click the Define metadata link.

    Define Metadata link
  5. Click Add.

  6. In Type id, enter a new message type ID, for example inbound-po.

  7. Click Create type.

  8. From the Type field in the Select metadata type window, select JSON or XML.

  9. In the Schema field, browse to the location of the schema file you imported in step 1, select the schema file, and click Open.

    The new EDIFACT message structure displays in the Input pane, and your application message structure displays in the Output pane:

    Message structures
    Edit current target icon
  10. Select File and save the DataWeave map with a meaningful name, such as INB-EDIFACT-D97A-ORDERS-to-Canonical-Purchase-Order-JSON.dwl.

  11. Modify the map to work with your schema.

The Template to create inbound and outbound EDIFACT message transformation contains a sample inbound EDIFACT to JSON mapping in the Mule configuration 01-inbound-edifact-json.xml file in the Transform component. The DataWeave file is in the src/main/resources/maps/EDIFACT_D97A_ORDERS_to_Canonical_PurchaseOrder_JSON.dwl file.

Test the Map Locally

Follow these steps to test the translation map locally in Anypoint Studio:

  1. In Package Explorer, right-click on the template project, and select Run > Run as Mule application.

  2. Use a REST client to post an EDI message payload to +http://localhost:8081/EDIFACT/inbound.

    The application returns the translated application message (JSON or XML) according to the mapping.

  3. After you verify that the map works correctly, copy the DataWeave map (dwl file) and import it to the Map section of your inbound EDIFACT message flow.

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub