In Business Central you can set up Change Log Entries to log insert/modify/delete events for all the fields in all the tables.

But can you do this automatically in the code without even setting up the Change Log Entry? It is quite easy actually.

Lets say we want to log the change every time someone updates Payment Reference on the Posted Purchase Invoice.

We would then create a procedure and attach it to the Purch. Inv. Header OnAfterModify event like this:

tableextension 50102 "Posted Invoice Header" extends "Purch. Inv. Header"
{
    trigger OnAfterModify()
    begin
        LogChange(Rec, xRec);
    end;

    local procedure LogChange(Rec: Record "Purch. Inv. Header"; xRec: Record "Purch. Inv. Header")
    var
        ChangeLogMgmt: Codeunit "Change Log Management";
        ChangeLogEntryType: enum "Change Log Entry Type";
        CurrentFieldRef: FieldRef;
        xFieldRef: FieldRef;
        CurrentRecRef: RecordRef;
        xRecRef: RecordRef;
        IsReadable: Boolean;
    begin
        if Rec."Payment Reference" <> xRec."Payment Reference" then begin
            CurrentRecRef.Open(Database::"Purch. Inv. Header");
            xRecRef.Open(Database::"Purch. Inv. Header");
            CurrentRecRef.Field(Rec.FieldNo("No.")).SetRange(Rec."No.");
            if CurrentRecRef.FindFirst() then begin
                xFieldRef := xRecRef.Field(xRec.FieldNo("Payment Reference"));
                CurrentFieldRef := CurrentRecRef.Field(Rec.FieldNo("Payment Reference"));
                if CurrentFieldRef.Active and xFieldRef.Active then begin
                    CurrentFieldRef.Value := Rec."Payment Reference";
                    xFieldRef.Value := xRec."Payment Reference";
                    if CurrentRecRef.ReadPermission then
                        IsReadable := true;
                    ChangeLogMgmt.InsertLogEntry(CurrentFieldRef, xFieldRef, CurrentRecRef, ChangeLogEntryType::Modification, IsReadable);
                    CurrentRecRef.Close();
                end;
            end;
        end;
    end;
}

This code will run and create the necessary change log entries without manually setting it up. Automatic Change Log Entries