Skip to content

Add two events to procedure "GetLastEntryNoFromTable" in codeunit 9500 "Sequence No. Mgt." #30328

Description

@complord

Why do you need this change?

Our app can apply global filters to the global dimension fields on ledger tables which may cause the GetLastEntryNoFromTable procedure to not get the correct last entry no.

Describe the request

In procedure "GetLastEntryNoFromTable" in codeunit 9500 "Sequence No. Mgt.", we would like to add one event at the beginning of the procedure and one event at the end so the filter(s) can be removed before then reapplied after.

Current:

    local procedure GetLastEntryNoFromTable(TableNo: Integer; WithLock: Boolean): BigInteger
    var
        [SecurityFiltering(SecurityFilter::Ignored)]
        RecRef: RecordRef;
        FldRef: FieldRef;
        KeyRef: KeyRef;
        LastEntryNo: BigInteger;
    begin
        RecRef.Open(TableNo);
        if WithLock then
            RecRef.ReadIsolation(IsolationLevel::UpdLock)
        else
            RecRef.ReadIsolation(IsolationLevel::ReadUncommitted);
        KeyRef := RecRef.KeyIndex(1);
        RecRef.SetLoadFields(KeyRef.FieldIndex(KeyRef.FieldCount).Number);
        if RecRef.FindLast() then begin
            FldRef := KeyRef.FieldIndex(KeyRef.FieldCount);
            LastEntryNo := FldRef.Value
        end else
            LastEntryNo := 0;
        exit(LastEntryNo);
    end;

Requested:

    local procedure GetLastEntryNoFromTable(TableNo: Integer; WithLock: Boolean): BigInteger
    var
        [SecurityFiltering(SecurityFilter::Ignored)]
        RecRef: RecordRef;
        FldRef: FieldRef;
        KeyRef: KeyRef;
        LastEntryNo: BigInteger;
    begin
        OnBeforeGetLastEntryNoFromTable(TableNo);               //NEW
        RecRef.Open(TableNo);
        if WithLock then
            RecRef.ReadIsolation(IsolationLevel::UpdLock)
        else
            RecRef.ReadIsolation(IsolationLevel::ReadUncommitted);
        KeyRef := RecRef.KeyIndex(1);
        RecRef.SetLoadFields(KeyRef.FieldIndex(KeyRef.FieldCount).Number);
        if RecRef.FindLast() then begin
            FldRef := KeyRef.FieldIndex(KeyRef.FieldCount);
            LastEntryNo := FldRef.Value
        end else
            LastEntryNo := 0;
        OnAfterGetLastEntryNoFromTable(TableNo);               //NEW
        exit(LastEntryNo);
    end;

    [IntegrationEvent(false, false)]
    local procedure OnBeforeGetLastEntryNoFromTable(TableNo: Integer)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnAfterGetLastEntryNoFromTable(TableNo: Integer)
    begin
    end;

Internal work item: AB#641557

Metadata

Metadata

Assignees

No one assigned

    Labels

    IntegrationGitHub request for Integration areaevent-requestRequest for adding an event

    Type

    Fields

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions