How to Call OnAfterInsertEvent (Table) Trigger Event via EventSubscriber

OnAfterInsertEvent (Table) Trigger Event via EventSubscriber:

What is an Event?

To handle events, you design event subscribers. Event subscribers determine what actions to take in response to an event that has been raised. An event subscriber is a method that listens for a specific event that is raised by an event publisher.

There can be multiple subscribers to the same event from various locations in the application code. When an event is raised, the subscriber methods are run one at a time in no particular order. You can’t specify the order in which the subscriber methods are called.

OnAfterInsertEvent (Table) Trigger Event:

It’s executed after a record is inserted in a table.


[EventSubscriber(ObjectType::Table, Database::<Table Name>, ‘OnAfterInsertEvent’, ”,
<SkipOnMissingLicense>, <SkipOnMissingPermission>)]
local procedure MyProcedure(Rec: Record, RunTrigger: Boolean)


Create dimension at the time of Sales Order “No.” generation. As shown in the figure.

Create dimension at the time of Sales order number generation- dynamics 365 BC

Source Code:

codeunit 50001 “Custom Functions-01”
    trigger OnRun()
    [EventSubscriber(ObjectType::Table, Database::”Sales Header”, ‘OnAfterInsertE
vent’, ”, true, true)]
    procedure OnAfterInsertValueInSO(Rec: Record “Sales Header”; Runtrigger: Bool
        DimensionValue: Record “Dimension Value”;
        GeneralLedgerSetup: Record “General Ledger Setup”;
        InsertDimensionValue: Record “Dimension Value”;
        GeneralLedgerSetup.testfield(“Global Dimension 1 Code”);
        DimensionValue.setrange(“Dimension Code”, GeneralLedgerSetup.”Global Dime
nsion 1 Code”);
        DimensionValue.setrange(Code, Rec.”No.”);
        if not DimensionValue.FindFirst() then begin
            InsertDimensionValue.validate(“Dimension Code”, GeneralLedgerSetup.”G
lobal Dimension 1 Code”);
            InsertDimensionValue.validate(“Code”, Rec.”No.”);
            InsertDimensionValue.validate(“Global Dimension No.”, 1);
            InsertDimensionValue.Validate(Name, Rec.”No.”);

How to change Caption or Name of existing Field in D365 BC
How to make Field Editable & Non-Editable and Visible & Non Visible in D365 BC
D365 BC Shows Error When Changes Made in Table Fields- Solved
OnAfterInsertEvent (Table) Trigger Event– Microsoft Docs

Leave a Reply