# Events after creating a Core document (DXP Document)

## Audience

This documentation is intended for third-party developers who want to extend the lifecycle of the Core document **`DXP Document`** – in particular at the points where:

- the status / "Next Process Step" is evaluated,
- `JSON Raw` / `JSON Processed` is updated,
- standard documents are created (for example purchase documents),
- attachments are transferred.

## Context: Core document creation vs. further processing

### 1) The Core document is created (`AddDocument`)

A `DXP Document` is created in **`DXP Document Mgt.`** via `AddDocument(...)`:

- The status is set to **Imported**.
- `JSON Raw` is written (if present) to a BLOB field.

### 2) Afterwards: transfer/linking and processing

Typical next steps (depending on the app flow):

- Linking to a source document (for example a SQUEEZE header) via `UpdateDocumentAfterTransfer(...)`
- Creating a standard document and writing `JSON Processed` via `UpdateDocument(...)`

Most extension points are therefore **not directly at the insert**, but in the update/processing flow.

## Event matrix (short overview)

<table id="bkmrk-area-event-timing-co"><thead><tr><th>Area</th><th>Event</th><th>Timing</th><th>Control</th><th>Typical use cases</th></tr></thead><tbody><tr><td><code>DXP Document Mgt&#46;</code></td><td>[<code>OnAfterSetLinkedToRecIdOnBeforeModify</code>](https://docs.squeeze.one/link/940#bkmrk-onaftersetlinkedtore)</td><td>in <code>UpdateDocumentAfterTransfer&#40;&#46;&#46;&#46;&#41;</code> before <code>Modify&#40;true&#41;</code></td><td>–</td><td>set additional info as soon as <code>Linked&#45;to Record Id</code> is set</td></tr><tr><td><code>DXP Document Mgt&#46;</code></td><td>[<code>OnBeforeGetDocumentOnBeforeCheckStatusAndNextProcessStep</code>](https://docs.squeeze.one/link/940#bkmrk-onbeforegetdocumento)</td><td>early in <code>UpdateDocument&#40;&#46;&#46;&#46;&#41;</code> before <code>Document&#46;Get&#40;DocNo&#41;</code></td><td><code>IsHandled</code></td><td>overwrite status/next step, take over processing</td></tr><tr><td><code>DXP Document Mgt&#46;</code></td><td>[<code>OnAfterGetDocumentOnBeforeCheckStatusAndNextProcessStep</code>](https://docs.squeeze.one/link/940#bkmrk-onaftergetdocumenton)</td><td>in <code>UpdateDocument&#40;&#46;&#46;&#46;&#41;</code> after <code>Get&#40;&#46;&#46;&#46;&#41;</code> before standard document creation</td><td><code>Handled</code></td><td>decide depending on the document, adjust JSON/status</td></tr><tr><td><code>DXP Document Mgt&#46;</code></td><td>[<code>OnAfterUpdateRawJson</code>](https://docs.squeeze.one/link/940#bkmrk-onafterupdaterawjson)</td><td>after writing <code>JSON Raw</code> in <code>UpdateRawJsonJson&#40;&#46;&#46;&#46;&#41;</code></td><td>–</td><td>normalize raw JSON/additional derivations</td></tr><tr><td><code>DXP Document Mgt&#46;</code></td><td>[<code>OnAfterWriteProcessedJsonToBlob</code>](https://docs.squeeze.one/link/940#bkmrk-onafterwriteprocesse)</td><td>after writing <code>JSON Processed</code> in <code>UpdateStatusAndProcessedJson&#40;&#46;&#46;&#46;&#41;</code></td><td>–</td><td>finalize processed JSON, add tokens</td></tr><tr><td><code>DXP Document Mgt&#46;</code></td><td>[<code>OnBeforeTransferCoreAttachmentsToStandardDocument</code>](https://docs.squeeze.one/link/940#bkmrk-onbeforetransfercore)</td><td>before the attachment transfer</td><td><code>IsHandled</code></td><td>replace/selectively control the transfer</td></tr><tr><td><code>DXP Document Transfer Mgt&#46;</code></td><td>[<code>OnBeforeExitProcessedJsonDocHeader</code>](https://docs.squeeze.one/link/940#bkmrk-onbeforeexitprocesse)</td><td>when creating header JSON (before <code>exit&#40;JObject&#41;</code>)</td><td>–</td><td>add/normalize standard tokens</td></tr><tr><td><code>DXP Document Transfer Mgt&#46;</code></td><td>[<code>OnBeforeExitProcessedJsonDocLine</code>](https://docs.squeeze.one/link/940#bkmrk-onbeforeexitprocesse-0)</td><td>when creating line JSON (before <code>exit&#40;JObject&#41;</code>)</td><td>–</td><td>add/normalize line tokens</td></tr><tr><td><code>DXP Document Transfer Mgt&#46;</code></td><td>[<code>OnAfterCreatePurchaseHeader</code>](https://docs.squeeze.one/link/940#bkmrk-onaftercreatepurchas)</td><td>after creating/validating the purchase header</td><td>–</td><td>add header fields, post-processing</td></tr><tr><td><code>DXP Document Transfer Mgt&#46;</code></td><td>[<code>OnBeforeInsertPurchaseLine</code>](https://docs.squeeze.one/link/940#bkmrk-onbeforeinsertpurcha)</td><td>before inserting a purchase line</td><td>–</td><td>adjust purchase line (for example account assignment, type/no.)</td></tr><tr><td><code>DXP Document Transfer Mgt&#46;</code></td><td>[<code>OnAfterInsertPurchaseLineOnBeforeAddDimensions</code>](https://docs.squeeze.one/link/940#bkmrk-onafterinsertpurchas)</td><td>after insert, before dimensions</td><td>–</td><td>prepare dimensions/additional info</td></tr><tr><td><code>DXP Document Transfer Mgt&#46;</code></td><td>[<code>OnAfterOnBeforeAddLineDimensions</code>](https://docs.squeeze.one/link/940#bkmrk-onafteronbeforeaddli)</td><td>for receipt lines: before the dimensions of the line to be updated</td><td>–</td><td>adjust update cases (receipt)</td></tr><tr><td><code>DXP Document Transfer Mgt&#46;</code></td><td>[<code>OnAfterProcessAdditionalInformation</code>](https://docs.squeeze.one/link/940#bkmrk-onafterprocessadditi)</td><td>after transferring additional information</td><td>–</td><td>add add-on fields per target RecordRef</td></tr><tr><td><code>DXP Document Transfer Mgt&#46;</code></td><td>[<code>OnAfterCreatePurchaseDoc</code>](https://docs.squeeze.one/link/940#bkmrk-onaftercreatepurchas-0)</td><td>after the complete creation of the purchase document</td><td>–</td><td>final hook (logging, follow-up actions)</td></tr></tbody></table>

---

## Events in `DXP Document Mgt.` (Core lifecycle)

### `OnAfterSetLinkedToRecIdOnBeforeModify`

Raised in `UpdateDocumentAfterTransfer(...)` – after the status/`Linked-to Record Id` have been set, but **before** the `DXP Document` is saved.

Signature:

```al
[IntegrationEvent(false, false)]
local procedure OnAfterSetLinkedToRecIdOnBeforeModify(var Document: Record "DXP Document")

```

Use cases:

- set additional information on the Core document as soon as it is linked to a source document
- add your own logging/audit information

### `OnBeforeGetDocumentOnBeforeCheckStatusAndNextProcessStep`

Called in `UpdateDocument(...)` as the **earliest hook** – even before the `DXP Document` is loaded via `Get(DocNo)`.

Signature:

```al
[IntegrationEvent(false, false)]
local procedure OnBeforeGetDocumentOnBeforeCheckStatusAndNextProcessStep(
    DocNo: Code[20];
    var Status: Enum "DXP Document Status";
    var NextStep: Enum "DXP Next Process Step";
    JObject: JsonObject;
    var IsHandled: Boolean)

```

Use cases:

- overwrite status/next step in advance (for example "Custom Processing")
- take over the complete processing (`IsHandled := true`)

### `OnAfterGetDocumentOnBeforeCheckStatusAndNextProcessStep`

Raised in `UpdateDocument(...)` after `Document.Get(DocNo)`, before standard documents are created.

Signature:

```al
[IntegrationEvent(false, false)]
local procedure OnAfterGetDocumentOnBeforeCheckStatusAndNextProcessStep(
    var Document: Record "DXP Document";
    NewStatus: Enum "DXP Document Status";
    NextStep: Enum "DXP Next process step";
    var ProcessedJSONObj: JsonObject;
    var Handled: Boolean)

```

Use cases:

- decide, depending on the current Core document, whether processing should be taken over
- adjust the `ProcessedJSONObj` before further processing

### `OnAfterUpdateRawJson`

Raised in `UpdateRawJsonJson(...)` after writing `JSON Raw`.

Signature:

```al
[IntegrationEvent(false, false)]
local procedure OnAfterUpdateRawJson(var Document: Record "DXP Document"; var RawJSONObj: JsonObject)

```

Use cases:

- validation/normalization steps on `RawJSONObj`
- additional data extraction directly after the raw update

### `OnAfterWriteProcessedJsonToBlob`

Raised in `UpdateStatusAndProcessedJson(...)` after `JSON Processed` has been written to the BLOB.

Signature:

```al
[IntegrationEvent(false, false)]
local procedure OnAfterWriteProcessedJsonToBlob(var Document: Record "DXP Document"; var ProcessedJSONObj: JsonObject)

```

Use cases:

- add additional tokens
- finalize the data structure before downstream processes access it

### `OnBeforeTransferCoreAttachmentsToStandardDocument`

Raised in `TransferCoreAttachmentsToStandardDocument(...)` before the transfer. The standard logic can be replaced via `IsHandled`.

Signature:

```al
[IntegrationEvent(false, false)]
local procedure OnBeforeTransferCoreAttachmentsToStandardDocument(Document: Record "DXP Document"; var IsHandled: Boolean)

```

Use cases:

- take over the attachment transfer completely (for example different storage/naming)
- restrict the transfer selectively

---

## Events in `DXP Document Transfer Mgt.` (standard documents from `JSON Processed`)

This codeunit is relevant as soon as standard documents (for example purchase documents) are created from `JSON Processed`.

### `OnBeforeExitProcessedJsonDocHeader`

Raised in `CreateDocHeaderJson(...)` immediately before `exit(JObject)`.

Signature:

```al
[IntegrationEvent(false, false)]
local procedure OnBeforeExitProcessedJsonDocHeader(var JObject: JsonObject)

```

Use cases:

- add additional standard tokens
- normalize token values (for example type/text representation)

### `OnBeforeExitProcessedJsonDocLine`

Raised in `CreateDocLineJson(...)` immediately before `exit(JObject)`.

Signature:

```al
[IntegrationEvent(false, false)]
local procedure OnBeforeExitProcessedJsonDocLine(var JObject: JsonObject)

```

Use cases:

- add/normalize line tokens

### `OnAfterCreatePurchaseHeader`

Raised after the purchase header is created/validated.

Signature:

```al
[IntegrationEvent(false, false)]
local procedure OnAfterCreatePurchaseHeader(var JObject: JsonObject; PurchaseHeader: Record "Purchase Header")

```

Use cases:

- set additional fields on the `Purchase Header` (for example custom references)
- post-processing/logging

### `OnBeforeInsertPurchaseLine`

Raised immediately before a purchase line is inserted.

Signature:

```al
[IntegrationEvent(false, false)]
local procedure OnBeforeInsertPurchaseLine(var JObjectLine: JsonObject; var PurchaseLine: Record "Purchase Line")

```

Use cases:

- adjust the purchase line (for example account assignment, type/no.)

### `OnAfterInsertPurchaseLineOnBeforeAddDimensions`

Raised after the purchase line is inserted, but before dimension validation.

Signature:

```al
[IntegrationEvent(false, false)]
local procedure OnAfterInsertPurchaseLineOnBeforeAddDimensions(var JObjectLine: JsonObject; PurchaseLine: Record "Purchase Line")

```

Use cases:

- prepare dimensions/additional info

### `OnAfterOnBeforeAddLineDimensions`

Raised in the receipt line update case, before dimensions are set for the purchase line to be updated.

Signature:

```al
[IntegrationEvent(false, false)]
local procedure OnAfterOnBeforeAddLineDimensions(var JObjectLine: JsonObject; PurchaseLineToUpdate: Record "Purchase Line")

```

Use cases:

- adjust update cases (receipt)

### `OnAfterProcessAdditionalInformation`

Raised after the transfer of additional information (`ProcessAdditionalInformation`).

Signature:

```al
[IntegrationEvent(false, false)]
local procedure OnAfterProcessAdditionalInformation(var RecRef: RecordRef; SourceJsonObject: JsonObject)

```

Use cases:

- add add-on fields for different target tables (header/line)

### `OnAfterCreatePurchaseDoc`

Raised after the complete creation of the purchase document.

Signature:

```al
[IntegrationEvent(false, false)]
local procedure OnAfterCreatePurchaseDoc(var JObject: JsonObject; PurchaseHeader: Record "Purchase Header")

```

Use cases:

- final hook (post-processing, logging, follow-up actions)

---

## Minimal example: influencing status/next step toward "Custom Processing"

Example: set `Status` to "Custom Processing" before the standard processing:

```al
codeunit 50101 "My Core Document Hooks"
{
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"DXP Document Mgt.", 'OnBeforeGetDocumentOnBeforeCheckStatusAndNextProcessStep', '', false, false)]
    local procedure OnBeforeGetDoc(
        DocNo: Code[20];
        var Status: Enum "DXP Document Status";
        var NextStep: Enum "DXP Next Process Step";
        JObject: JsonObject;
        var IsHandled: Boolean)
    begin
        Status := Status::"Custom Processing";
        // optionally adjust NextStep
    end;
}

```

<p class="callout info">\[Best Practice\] Use `IsHandled := true` only when you fully replace the standard logic – otherwise it can lead to inconsistent status/JSON states.</p>