Creating a Translation Map For XML or JSON to Outbound EDIFACT

Use the MuleSoft template named Template to create inbound and outbound EDIFACT message transformation to help you map application messages from canonical formats such as XML or JSON to outbound EDI EDIFACT messages to send to your trading partners.

This template uses DataWeave in Anypoint Studio to create the mapping between the XML or JSON format and the EDIFACT format. To use the template to create the mapping:

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

  2. Set the source message type.

  3. Set the Target EDIFACT Message Type

  4. Test the map locally.

Create a New Project From a Template

Create a template project in Anypoint Studio and import a DataWeave map template that maps outbound EDIFACT transactions to an application format:

  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 02-outbound-edifact-transform.xml in the downloaded template.

Set the Source Message Type

Set the source message type to define the metadata structure of your application message, such as XML or JSON:

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

  2. Select the 02-outbound-edifact-transform.xml flow.

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

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

    Define Metadata link
  5. Click Add.

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

  7. Click Create type.

  8. In the Select metadata type window, from the Type field, select JSON or XML.

  9. Browse to the location of the JSON or XML schema file you imported in step 1 and click Select.

Set the Target EDIFACT Message Type

The template 02-outbound-edifact-transform.xml is configured with the EDIFACT version D97A, ORDRSP message type. Follow these steps to change the target EDIFACT message type:

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

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

  3. Select EDIFACT_Write and click Edit.

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

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

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

    The new EDIFACT message structure displays in the output pane, and your application message structure (JSON or XML) displays in the input pane:

    EDIFACT and application message structures
  6. Click the Edit current target icon:

    Edit current target icon
  7. Modify the map to work with your schema.

The Template to create inbound and outbound EDIFACT message transformation contains a sample mapping to transform the canonical JSON message structure into D97A ORDRSP messages. This mapping is in the configuration 02-outbound-edifact-json.xml file in the Transform component. The DataWeave file is src/main/resources/maps/Canonical_PO_Ack_JSON_to_EDIFACT_D97A_ORDRSP file.

Test the Map Locally

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

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

  2. Use a REST client to post a JSON or an XML payload to http://localhost:8081/edifact/outbound

    The application returns the transformed EDIFACT transaction.

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

Was this article helpful?

💙 Thanks for your feedback!

View on GitHub