ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

[W1][Table][179][Reversal Entry] CheckBankAcc - skip Open / Statement No. checks

Open MortegaITB opened this issue 3 months ago • 2 comments

Why do you need this change?

We need more flexibility when working with Bank Account Ledger Entries in custom processes and integrations.

Currently, CheckBankAcc (table 179 "Reversal Entry") enforces two strict validations that raise errors when:

  • The entry is not open (not BankAccountLedgerEntry.Open)
  • The entry has a Statement No. assigned (BankAccountLedgerEntry."Statement No." <> '')

These validations prevent us from reusing standard reversal logic in scenarios such as automated integrations, data correction processes, controlled reversals or reprocessing, and custom financial workflows. Since these two errors are hardcoded and not individually extensible, we cannot override or bypass either one independently using standard event subscribers today. This forces us to duplicate standard logic or modify base code, which is not maintainable.

Alternatives evaluated:

  • Using the existing OnBeforeCheckBankAcc event as-is: Rejected as a full solution. It only exposes IsHandled, which fires before the entire CheckBankAcc procedure and bypasses all validations at once if set ΓÇö including the posting-date check, the blocked-account check, the already-reversed check, and the check-ledger-entry check, which we want to keep. Our need is more granular: suppress only the Open check or only the Statement No. check independently, depending on the scenario, while preserving the rest of the procedure's behavior.
  • Adding two brand-new event publishers instead of extending OnBeforeCheckBankAcc: Considered, but rejected in favor of extending the existing event. OnBeforeCheckBankAcc already fires once per CheckBankAcc call, so subscribers only need to bind to one event and can independently decide whether to skip the whole procedure (IsHandled) or just one specific check, rather than binding to three separate events for the same procedure call.
  • TryFunction wrapper: Rejected. It silently swallows all errors without discriminating between them, which isn't safe or maintainable for a procedure that performs several distinct checks.
  • Duplicating CheckBankAcc in a custom codeunit: Rejected. Creates a maintenance liability with every BC update, since the procedure would need to be kept in sync manually.

Why named Skip parameters, not a second generic IsHandled: the two checks are logically independent ΓÇö an integration may legitimately need to skip only one of them ΓÇö so a single additional flag would force an all-or-nothing choice we don't need. Adding two specifically named parameters (SkipBankAccLedgEntryOpenCheck, SkipBankAccLedgEntryStatementNoCheck) to the existing event documents exactly what each one skips and lets any subscriber independently control either check, without the "first subscriber wins" ambiguity of a shared generic flag.

Benefit: partners/customers can reuse the standard CheckBankAcc validation logic in automated integrations and reprocessing scenarios, selectively skipping only the specific check(s) that don't apply to their scenario, without duplicating or bypassing the rest of the procedure's safety checks, and without having to bind to multiple new events.

Describe the request

Add two new var Boolean parameters ΓÇö SkipBankAccLedgEntryOpenCheck and SkipBankAccLedgEntryStatementNoCheck ΓÇö to the existing event publisher OnBeforeCheckBankAcc in table 179 "Reversal Entry", appended after the existing IsHandled parameter, and use them in CheckBankAcc to guard each corresponding Error() call independently.

Before:

local procedure CheckBankAcc(BankAccountLedgerEntry: Record "Bank Account Ledger Entry")
var
    BankAccount: Record "Bank Account";
    CheckLedgerEntry: Record "Check Ledger Entry";
    IsHandled: Boolean;
begin
    IsHandled := false;
    OnBeforeCheckBankAcc(BankAccountLedgerEntry, IsHandled);
    if IsHandled then
        exit;

    BankAccount.Get(BankAccountLedgerEntry."Bank Account No.");
    JnlTemplName := BankAccountLedgerEntry."Journal Templ. Name";
    CheckPostingDate(BankAccountLedgerEntry."Posting Date", BankAccountLedgerEntry.TableCaption(), BankAccountLedgerEntry."Entry No.");
    BankAccount.TestField(Blocked, false);
    if BankAccountLedgerEntry.Reversed then
        AlreadyReversedEntry(BankAccountLedgerEntry.TableCaption(), BankAccountLedgerEntry."Entry No.");
    if not BankAccountLedgerEntry.Open then
        Error(
          Text006, BankAccountLedgerEntry.TableCaption(), BankAccountLedgerEntry."Entry No.");
    if BankAccountLedgerEntry."Statement No." <> '' then
        Error(
          Text007, BankAccountLedgerEntry.TableCaption(), BankAccountLedgerEntry."Entry No.");
    CheckLedgerEntry.SetRange("Bank Account Ledger Entry No.", BankAccountLedgerEntry."Entry No.");
    if not CheckLedgerEntry.IsEmpty() then
        Error(
          Text003, BankAccountLedgerEntry.TableCaption(), BankAccountLedgerEntry."Entry No.");

    OnAfterCheckBankAcc(BankAccount, BankAccountLedgerEntry);
end;

[IntegrationEvent(false, false)]
local procedure OnBeforeCheckBankAcc(BankAccountLedgerEntry: Record "Bank Account Ledger Entry"; var IsHandled: Boolean)
begin
end;

After:

local procedure CheckBankAcc(BankAccountLedgerEntry: Record "Bank Account Ledger Entry")
var
    BankAccount: Record "Bank Account";
    CheckLedgerEntry: Record "Check Ledger Entry";
    IsHandled: Boolean;
    SkipBankAccLedgEntryOpenCheck: Boolean;
    SkipBankAccLedgEntryStatementNoCheck: Boolean;
begin
    IsHandled := false;
    SkipBankAccLedgEntryOpenCheck := false;
    SkipBankAccLedgEntryStatementNoCheck := false;
    OnBeforeCheckBankAcc(BankAccountLedgerEntry, IsHandled, SkipBankAccLedgEntryOpenCheck, SkipBankAccLedgEntryStatementNoCheck);
    if IsHandled then
        exit;

    BankAccount.Get(BankAccountLedgerEntry."Bank Account No.");
    JnlTemplName := BankAccountLedgerEntry."Journal Templ. Name";
    CheckPostingDate(BankAccountLedgerEntry."Posting Date", BankAccountLedgerEntry.TableCaption(), BankAccountLedgerEntry."Entry No.");
    BankAccount.TestField(Blocked, false);
    if BankAccountLedgerEntry.Reversed then
        AlreadyReversedEntry(BankAccountLedgerEntry.TableCaption(), BankAccountLedgerEntry."Entry No.");
    if not SkipBankAccLedgEntryOpenCheck then
        if not BankAccountLedgerEntry.Open then
            Error(
              Text006, BankAccountLedgerEntry.TableCaption(), BankAccountLedgerEntry."Entry No.");
    if not SkipBankAccLedgEntryStatementNoCheck then
        if BankAccountLedgerEntry."Statement No." <> '' then
            Error(
              Text007, BankAccountLedgerEntry.TableCaption(), BankAccountLedgerEntry."Entry No.");
    CheckLedgerEntry.SetRange("Bank Account Ledger Entry No.", BankAccountLedgerEntry."Entry No.");
    if not CheckLedgerEntry.IsEmpty() then
        Error(
          Text003, BankAccountLedgerEntry.TableCaption(), BankAccountLedgerEntry."Entry No.");

    OnAfterCheckBankAcc(BankAccount, BankAccountLedgerEntry);
end;

[IntegrationEvent(false, false)]
local procedure OnBeforeCheckBankAcc(BankAccountLedgerEntry: Record "Bank Account Ledger Entry"; var IsHandled: Boolean; var SkipBankAccLedgEntryOpenCheck: Boolean; var SkipBankAccLedgEntryStatementNoCheck: Boolean)
begin
end;

This is a minimal, additive signature change ΓÇö two new var Boolean parameters appended to the end of the existing event, per Microsoft's own guidance ("Add new variables to the end of an existing event. However, you can't change existing variables because that would cause a breaking change."). No new event is introduced, no other check in the procedure is touched, and existing subscribers to OnBeforeCheckBankAcc that only use IsHandled are unaffected since the two new parameters default to false.

Illustrative subscriber:

[EventSubscriber(ObjectType::Table, Table::"Reversal Entry", 'OnBeforeCheckBankAcc', '', false, false)]
local procedure SkipSpecificChecksForControlledReversal(BankAccountLedgerEntry: Record "Bank Account Ledger Entry"; var IsHandled: Boolean; var SkipBankAccLedgEntryOpenCheck: Boolean; var SkipBankAccLedgEntryStatementNoCheck: Boolean)
begin
    // e.g. allow reversal of a closed, already-reconciled entry during a controlled
    // data-correction process, while keeping all other CheckBankAcc validations active
    SkipBankAccLedgEntryOpenCheck := true;
    SkipBankAccLedgEntryStatementNoCheck := true;
end;

Performance considerations: OnBeforeCheckBankAcc already fires once per CheckBankAcc call, which runs once per Bank Account Ledger Entry being reversed ΓÇö a targeted, entry-level operation (manual reconciliation, reversal, controlled integration), never a large-dataset loop. Adding two more boolean out-parameters to an event call that already exists has no measurable additional overhead; if no subscriber is registered, both new flags simply stay false and every check runs exactly as before.

Data sensitivity review: the only parameters exposed are BankAccountLedgerEntry (table 271, already exposed in existing standard events such as OnAfterBankAccLedgEntryInsert, OnBeforeCloseBankAccountLedgerEntry) and the boolean control variables. No new security surface, no write access to the record, no passwords, keys, or additional GDPR-relevant data beyond what standard permissions already expose.

Multi-extension interaction: because SkipBankAccLedgEntryOpenCheck and SkipBankAccLedgEntryStatementNoCheck are independent, specifically named parameters, any subscriber that sets one of them to true causes only that specific check to be skipped ΓÇö there's no ambiguity about which check is affected, and no interaction with IsHandled, which still governs skipping the entire procedure as before. Worst case with multiple extensions installed, a check is skipped that another extension might have wanted enforced; this is the intended, documented behavior of setting the flag, not a bug, and carries no risk of data corruption or inconsistent state. Existing behavior for subscribers using only IsHandled is fully preserved. Internal work item: AB#647663

MortegaITB avatar Aug 24 '26 08:08 MortegaITB

✅ Analysis complete - ready for further processing


Implementation:

Extend OnBeforeCheckBankAcc with two trailing var Boolean parameters and use them in CheckBankAcc() to independently skip the Open and Statement No. validations while preserving the remaining checks.

Location in CheckBankAcc() procedure:

IsHandled := false;
SkipBankAccLedgEntryOpenCheck := false;
SkipBankAccLedgEntryStatementNoCheck := false;
OnBeforeCheckBankAcc(BankAccountLedgerEntry, IsHandled, SkipBankAccLedgEntryOpenCheck, SkipBankAccLedgEntryStatementNoCheck);
if IsHandled then
    exit;

BankAccount.Get(BankAccountLedgerEntry."Bank Account No.");
JnlTemplName := BankAccountLedgerEntry."Journal Templ. Name";
CheckPostingDate(BankAccountLedgerEntry."Posting Date", BankAccountLedgerEntry.TableCaption(), BankAccountLedgerEntry."Entry No.");
BankAccount.TestField(Blocked, false);
if BankAccountLedgerEntry.Reversed then
    AlreadyReversedEntry(BankAccountLedgerEntry.TableCaption(), BankAccountLedgerEntry."Entry No.");
if (not SkipBankAccLedgEntryOpenCheck) and (not BankAccountLedgerEntry.Open) then
    Error(
      Text006, BankAccountLedgerEntry.TableCaption(), BankAccountLedgerEntry."Entry No.");
if (not SkipBankAccLedgEntryStatementNoCheck) and (BankAccountLedgerEntry."Statement No." <> '') then
    Error(
      Text007, BankAccountLedgerEntry.TableCaption(), BankAccountLedgerEntry."Entry No.");
CheckLedgerEntry.SetRange("Bank Account Ledger Entry No.", BankAccountLedgerEntry."Entry No.");
if not CheckLedgerEntry.IsEmpty() then
    Error(
      Text003, BankAccountLedgerEntry.TableCaption(), BankAccountLedgerEntry."Entry No.");

OnAfterCheckBankAcc(BankAccount, BankAccountLedgerEntry);

Event Publisher (add at the end of the codeunit with other events):

[IntegrationEvent(true, false)]
local procedure OnBeforeCheckBankAcc(var BankAccLedgEntry: Record "Bank Account Ledger Entry"; var IsHandled: Boolean; var SkipBankAccLedgEntryOpenCheck: Boolean; var SkipBankAccLedgEntryStatementNoCheck: Boolean)
begin
end;

File: ReversalEntry.Table.al

[!NOTE] Automatically generated by the Triage Agent — advisory only. An engineer will review before any action is taken.

[!TIP] Not accurate? Reply with /not-accurate (optional: add a short explanation). Your feedback improves future responses.

github-actions[bot] avatar Aug 24 '26 13:08 github-actions[bot]

fixed

AndersLarsenMicrosoft avatar Sep 01 '26 14:09 AndersLarsenMicrosoft