Skip to main content

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)

Area Event Timing Control Typical use cases
DXP Document Mgt. OnAfterSetLinkedToRecIdOnBeforeModify in UpdateDocumentAfterTransfer(...) before Modify(true) set additional info as soon as Linked-to Record Id is set
DXP Document Mgt. OnBeforeGetDocumentOnBeforeCheckStatusAndNextProcessStep early in UpdateDocument(...) before Document.Get(DocNo) IsHandled overwrite status/next step, take over processing
DXP Document Mgt. OnAfterGetDocumentOnBeforeCheckStatusAndNextProcessStep in UpdateDocument(...) after Get(...) before standard document creation Handled decide depending on the document, adjust JSON/status
DXP Document Mgt. OnAfterUpdateRawJson after writing JSON Raw in UpdateRawJsonJson(...) normalize raw JSON/additional derivations
DXP Document Mgt. OnAfterWriteProcessedJsonToBlob after writing JSON Processed in UpdateStatusAndProcessedJson(...) finalize processed JSON, add tokens
DXP Document Mgt. OnBeforeTransferCoreAttachmentsToStandardDocument before the attachment transfer IsHandled replace/selectively control the transfer
DXP Document Transfer Mgt. OnBeforeExitProcessedJsonDocHeader when creating header JSON (before exit(JObject)) add/normalize standard tokens
DXP Document Transfer Mgt. OnBeforeExitProcessedJsonDocLine when creating line JSON (before exit(JObject)) add/normalize line tokens
DXP Document Transfer Mgt. OnAfterCreatePurchaseHeader after creating/validating the purchase header add header fields, post-processing
DXP Document Transfer Mgt. OnBeforeInsertPurchaseLine before inserting a purchase line adjust purchase line (for example account assignment, type/no.)
DXP Document Transfer Mgt. OnAfterInsertPurchaseLineOnBeforeAddDimensions after insert, before dimensions prepare dimensions/additional info
DXP Document Transfer Mgt. OnAfterOnBeforeAddLineDimensions for receipt lines: before the dimensions of the line to be updated adjust update cases (receipt)
DXP Document Transfer Mgt. OnAfterProcessAdditionalInformation after transferring additional information add add-on fields per target RecordRef
DXP Document Transfer Mgt. OnAfterCreatePurchaseDoc after the complete creation of the purchase document final hook (logging, follow-up actions)

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:

[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:

[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:

[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:

[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:

[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:

[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:

[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:

[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:

[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:

[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:

[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:

[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:

[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:

[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:

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;
}

[Best Practice] Use IsHandled := true only when you fully replace the standard logic – otherwise it can lead to inconsistent status/JSON states.