Approval and rejection: reacting to it with an event

Who approved or rejected is recorded on the approval entry and in the audit trail. Many companies want to see it where they work anyway, though — on the document itself, in a report or in another system. Partners and customers with their own development can react to every decision for that: with an integration event that is raised after a person has approved or rejected, and that says who decided what, in which step.

This page is the developer contract: the event, its parameters, which way produces which values, and an example. Available from version 1.20.

Typical use

A company prints on its purchase orders who released them. It has a field of its own, "Approved By", on the purchase header. A subscriber writes the approver into it on every approval of the document; the workflow itself is untouched.

The event

Publisher: codeunit DXP AWF Approval Entry Helper, integration event OnAfterApprovalDecided. It is raised after the workflow has processed the decision — so the step may already have moved on, or the workflow may be completed. It runs in the same transaction as the decision.

ParameterMeaning
InstanceID: GuidThe workflow instance the approval belongs to.
SourceRecordID: RecordIdThe record the workflow runs for — the document, also when one of its lines was decided.
RecordID: RecordIdThe record that was decided — the document or one of its lines. For a decision on the document it equals SourceRecordID.
StageCode: Code[30]The step the decision was made in — before the workflow moved on to the next one.
Decision: Enum "DXP AWF User Action"Approve or Reject.
DecidedByUserID: Code[50]The Business Central user who decided. Empty for an external approver without a user of their own.
DecidedByEmail: TextThe e-mail address of whoever decided — for an external approver, the one the response came from.
Reason: TextThe rejection reason, or an external approver's comment. Empty where none was given.
ApprovalEntry: Record "Approval Entry"The decided approval entry, as it was when the decision was made — for anything else, such as the entry number or whether it is a related approval.

The decision is in Decision, not in the approval entry's Status. When a user rejects the document, Business Central sets its entry to Rejected only after this event.

DecidedByUserID and DecidedByEmail are the values the approval entry keeps in Decided By User ID and Decided By Email — what the Four-Eyes Check is built on. The event is raised exactly where those fields are written.

Which way produces which values

WayDecisionRecordIDReason
Approve — through the actions on the document, Requests to Approve, Approve Line(s), the Related approvals FactBox and Approve AllApprovedocument or lineempty
Reject the documentRejectdocumentthe rejection reason from the dialog
Reject Line(s) — also through the Related approvals FactBoxRejectlinethe rejection reason from the dialog
Reject AllRejecteach line first, the document lastthe reason entered once
External approval — a response from Microsoft Teams or Power AutomateApprove or Rejectdocument or linethe approver's comment

A user who receives their approval requests in Microsoft Teams is reported with their user ID there as well. An External Approver without a Business Central user has only an e-mail address; DecidedByUserID is then empty.

Approve All and Reject All raise the event once per decided entry. A group approval raises it once — for the group member who decided; the other members' entries are cancelled, not decided.

Example: writing the approver into the document

codeunit 50113 "MY AWF Approver Stamp"
{
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"DXP AWF Approval Entry Helper", 'OnAfterApprovalDecided', '', false, false)]
    local procedure StampApprover(InstanceID: Guid; SourceRecordID: RecordId; RecordID: RecordId; StageCode: Code[30]; Decision: Enum "DXP AWF User Action"; DecidedByUserID: Code[50]; DecidedByEmail: Text; Reason: Text; ApprovalEntry: Record "Approval Entry")
    var
        PurchaseHeader: Record "Purchase Header";
    begin
        if Decision <> Decision::Approve then
            exit;
        // Only the approval of the document itself, not those of its lines.
        if RecordID <> SourceRecordID then
            exit;
        if SourceRecordID.TableNo() <> Database::"Purchase Header" then
            exit;
        if not PurchaseHeader.Get(SourceRecordID) then
            exit;

        // An external approver without a user has only an e-mail address.
        if DecidedByUserID <> '' then
            PurchaseHeader."MY Approved By" := DecidedByUserID
        else
            PurchaseHeader."MY Approved By" := CopyStr(DecidedByEmail, 1, MaxStrLen(PurchaseHeader."MY Approved By"));
        PurchaseHeader."MY Approved At" := CurrentDateTime();
        PurchaseHeader.Modify(false);
    end;
}

Advanced Workflow's edit restriction applies to changes a user makes in the client — a subscriber that changes the document in code is not affected by it.

What the event does not do


Revision #1
Created 2026-12-01 19:33:52 UTC by Bernd Feddersen
Updated 2026-12-01 19:33:52 UTC by Bernd Feddersen