Skip to content

[W1][Codeunit][12][Gen. Jnl.-Post Line]` Add var NextEntryNo, var NextVATEntryNo, and var NextTransactionNo to OnAfterInitGLRegister in StartPosting #30276

@mavohra

Description

@mavohra

Why do you need this change?

We need to override the freshly initialized entry counters at the start of a G/L posting cycle with values captured from a prior posting cycle. When a G/L posting cycle follows another posting context that already created G/L entries and VAT entries, the next entry number, next VAT entry number, and next transaction number must continue sequentially rather than starting from freshly queried database values.

The standard StartPosting procedure calls InitNextEntryNo which sets NextEntryNo and NextTransactionNo from the last G/L entry in the database. It then initializes NextVATEntryNo from the last VAT entry. These values are used to set GLReg."From Entry No." and GLReg."From VAT Entry No.". There is no way for a subscriber to override these counter values before they are written into the register record.

The existing OnAfterInitGLRegister event fires after the GLReg record fields are set and passes GLReg as a var parameter. A subscriber can override the register record itself but cannot directly set NextEntryNo, NextVATEntryNo, or NextTransactionNo to values captured from a prior cycle. These counters are needed for subsequent ContinuePosting calls and for the OnBeforeContinuePosting event.

Describe the request

Add var NextEntryNo: Integer, var NextVATEntryNo: Integer, and var NextTransactionNo: Integer to the existing integration event OnAfterInitGLRegister in the StartPosting procedure in Codeunit 12 "Gen. Jnl.-Post Line". The new parameters follow the existing parameters at the end.

            GLReg."User ID" := CopyStr(UserId(), 1, MaxStrLen(GLReg."User ID"));
            IsGLRegInserted := false;

            OnAfterInitGLRegister(GLReg, GenJnlLine, NextEntryNo, NextVATEntryNo, NextTransactionNo); // <---- New parameters at end

            GetCurrencyExchRate(GenJnlLine);
            TempGLEntryBuf.DeleteAll();
            TempGLEntryPreview.DeleteAll();

Event Signature:

[IntegrationEvent(false, false)]
local procedure OnAfterInitGLRegister(var GLRegister: Record "G/L Register"; var GenJournalLine: Record "Gen. Journal Line"; var NextEntryNo: Integer; var NextVATEntryNo: Integer; var NextTransactionNo: Integer)
begin
end;

Alternatives evaluated: OnBeforeStartPosting fires at the very top of StartPosting before InitNextEntryNo runs, so the entry counters have not yet been resolved from the database. OnAfterStartPosting fires at the end of StartPosting after CalculateCurrentBalance has already used the freshly initialized register state. OnBeforeContinuePosting fires at the start of ContinuePosting and passes GLReg, NextEntryNo, and NextTransactionNo as var parameters but fires once per journal line rather than once per posting cycle and does not include NextVATEntryNo. No event currently allows overriding all entry counters together with the register record at the single initialization point.
Internal work item: AB#639006

Metadata

Metadata

Assignees

No one assigned

    Labels

    FinanceGitHub request for Finance areaevent-requestRequest for adding an event

    Type

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions