---
schema_version: "1"
id: c835a6dc17fe96bdb2c390b3d032c763a1d4befc875ad41189025b690cd619c7
title: X12 EDI Connector 3.0 Batch Outbound X12 Messages
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/x12-edi-connector/latest/x12-edi-connector-batching.md
canonical_url: https://docs.mulesoft.com/x12-edi-connector/latest/x12-edi-connector-batching
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 78723b7c7f31001eadcbe2b41371ae588bf871655cc9e982d4f86f25631d3834
description: MuleSoft Documentation Site
release: "3.0"
latest: true
---
---
product: X12 EDI Connector
version: 3.0
is-latest-version: true
---

# X12 EDI Connector 3.0 Batch Outbound X12 Messages

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

For EDI messages that are not time-sensitive, such as invoice and payment remittances, use the Write
batch operation to merge multiple individual messages into a single interchange to send to your
trading partners.

## Batching Stages

Implementing a batch involves two stages:

1.  Accumulate the transactions.

2.  Release the batch.

### Accumulate the Transactions

To accumulate transactions for a batch:

1.  Transform the payloads into X12 messages using DataWeave and X12 as you receive application
    messages (such as a JSON invoice) from the backend systems.

2.  Create X12 payloads using temporary control number keys in the X12 Write operation.

    This enables sending the accumulated X12 as a batch at a later time. The batch is created using
    control numbers that are not used in the final batch that is sent to the trading partner, for
    example,
    `<x12:write doc:name="Create a single X12 810 Invoice Txn" doc:id="767e1321-044d-4ed4-95ba-6ddc78efb0b4" config-ref="X12_EDI_Write_810" interchangeNumberKey="MYTHICAL-NTOETAIL-ISA-TMP" groupNumberKey="MYTHICAL-NTOETAIL-GS-TMP"/>`.

3.  Store the intermediate X12 message payloads in your choice of storage, such as a database table:

![Accumulate the transactions](/mulesoft/current/en-us/x12-edi-connector/latest/_images/X12-edi-connector-batch-flow-1.jpg)

For example, this implementation of a Mule flow:

- Receives JSON payloads from the backend systems.

- Transforms to an `X12 810` invoice message.

- Generates the intermediate X12 message payload using the X12 Write operation.

- Stores the X12 payload in a database table.

### Release the Batch

Trading partners have varying criteria for how they want transactions batched:

- Release the batch at a specific time interval or a specific time of the day.

- Release the batch when a specific number of transactions are accumulated.

- Release the batch when the total size of the accumulated transactions is near a specified
  threshold.

To release the batch:

1.  Implement the logic or module to monitor the transactions accumulated in the temporary storage
    and determine when a particular batch is released.

2.  Retrieve the accumulated intermediate X12 messages from the temporary storage based on the batch
    criteria, group the transactions together, and then send the appended payload to the X12 Write
    batch operation.

    Use the control number key on the Write batch operation, or leave the control number key fields
    empty during Write batch execution so that X12 EDI Connector generates the control number
    sequence automatically based on the sender and receiver identifier combination:

    `<x12:batch doc:name="Batch" doc:id="6f105235-1406-45bb-b41e-f3b28cdf2eb5" config-ref="X12_EDI_Batch" batchInterchangeNumberKey="MYTHICAL-NTOETAIL-ISA" batchGroupNumberKey="MYTHICAL-NTOETAIL-GS"> <x12:batch-content ><![CDATA[#[vars.batchInput]]]></x12:batch-content></x12:batch>`.

3.  Ensure that the input payload sent to the Write batch operation contains EDI transactions with
    data elements in the ISA and GS envelope segments, such as `Sender ID`, `Receiver ID`, and
    `Version number`:

![Release the batch](/mulesoft/current/en-us/x12-edi-connector/latest/_images/x12-edi-connector-batch-flow-2.png)

For example, this implementation of a Mule flow:

- Receives an HTTP request to release accumulated X12 messages transactions for a specific partner.
  The request is triggered after the batch release criteria are met.

- Retrieves the intermediate X12 messages from the database table.

- Applies a transformation to group the individual X12 messages.

- Sends the appended payload through the X12 Write batch operation to merge the messages into a
  single transaction.

- Prints the generated control numbers, which reconcile the inbound functional acknowledgments
  received from the partners.

- Delivers the batched X12 transaction to the trading partner’s SFTP site.

If the input payload contains EDI transactions with non-matching data elements in the envelope
segments, the Batch operation throws an exception.
