diff --git a/en/docs/develop/transform/edi.md b/en/docs/develop/transform/edi.md index c427fe5db16..ccd11387279 100644 --- a/en/docs/develop/transform/edi.md +++ b/en/docs/develop/transform/edi.md @@ -83,7 +83,7 @@ The generated file contains: - **`getSchema`**: returns the EDI schema as an `EdiSchema` object. - **`fromEdiStringWithSchema`** / **`toEdiStringWithSchema`**: variants that accept a pre-loaded `EdiSchema`, useful when the same code must handle multiple schemas selected at runtime. -## Adjusting a schema for a trading partner +## Adapting the schema to a trading partner Trading partners routinely use variations of a standard format: an extra segment, a segment the standard marks optional but the partner always sends, a different delimiter set, or a field the partner sends as a number where the standard says text. Because `convertEdifactSchema` and `convertX12Schema` write the schema out as JSON before any code is generated, a partner's deviations are handled by editing that file and re-running `codegen` — the standard specification itself is never touched. @@ -287,11 +287,12 @@ public function main() returns error? { orders:ORDERSInterchange interchange = check orders:interchangeFromEdiString(ediContent); foreach var txn in interchange.transactions { - if txn.body is error { - log:printError("Quarantined malformed transaction", 'error = txn.body); + orders:ORDERS|error body = txn.body; + if body is error { + log:printError("Quarantined malformed transaction", 'error = body); continue; } - log:printInfo(txn.body.toString()); + log:printInfo(body.toString()); } } ``` diff --git a/en/docs/reference/data-formats/edi.md b/en/docs/reference/data-formats/edi.md index cf0b138d04b..38c3f8369ef 100644 --- a/en/docs/reference/data-formats/edi.md +++ b/en/docs/reference/data-formats/edi.md @@ -157,11 +157,12 @@ public function main() returns error? { edi:EdiInterchange interchange = check edi:interchangeFromEdiString(ediText, schema); foreach var txn in interchange.transactions ?: [] { - if txn.body is error { - io:println("Quarantined: ", txn.body.message()); + json|error body = txn.body; + if body is error { + io:println("Quarantined: ", body.message()); continue; } - io:println(txn.body); + io:println(body); } } ``` @@ -185,7 +186,7 @@ For full signatures, parameters, error types (`InvalidEnvelopeError`, `SchemaCom ## Custom EDI schemas -For EDI formats not covered by prebuilt packages — or when you need to tune a generated schema for partner-specific variations — define the structure as a JSON schema. The following JSON schema defines the structure of the simple order EDI format shown above. +For a proprietary or non-standard format — one with no X12 or EDIFACT specification to convert from — define the structure directly as a JSON schema. The following JSON schema defines the structure of the simple order EDI format shown above. To handle a trading partner's variations on a *standard* format, start from the converted schema instead: see [Adapting the schema to a trading partner](../../develop/transform/edi.md#adapting-the-schema-to-a-trading-partner). ```json {