-
Notifications
You must be signed in to change notification settings - Fork 692
Description
Describe the bug
After posting a Bank Deposit, the confirmation dialog offers to open the Posted Bank Deposit card. When the user clicks Yes, the Posted Bank Deposit page opens showing the first record in the table instead of the deposit that was just posted.
To Reproduce
- Create a Bank Deposit with one or more lines
- Post the deposit
- Click "Yes" on the dialog asking to view the posted deposit
- The Posted Bank Deposit card opens showing the first-ever posted deposit, not the one just posted
Expected behavior
The Posted Bank Deposit card should open filtered to the deposit that was just posted.
Root Cause
The bug is in Codeunit 1690 "Bank Deposit-Post". The codeunit uses EventSubscriberInstance = Manual with BindSubscription, which creates two separate instances:
- Instance A (caller) — runs
OnRun()and callsPage.Run(Page::"Posted Bank Deposit", PostedBankDepositHeader)at the end - Instance B (bound subscriber) — receives event callbacks that populate
PostedBankDepositHeaderviaInsertPostedBankDepositHeader
The Page.Run at the end of OnRun() reads Instance A's PostedBankDepositHeader, which was never populated. The correctly populated record lives on Instance B. Passing an uninitialized record to Page.Run opens the page with no filter, so BC shows the first record in the table.
Relevant code flow in OnRun():
BankDepositPost.SetPostedBankDepositHeaderCreated(false);
BankDepositPost.SetCurrentDeposit(Rec);
BindSubscription(BankDepositPost); // Instance B receives events
GenJnlPostBatch.Run(GenJournalLine); // Populates Instance B's PostedBankDepositHeader
UnbindSubscription(BankDepositPost);
// ...
if ShowDialog then
Page.Run(Page::"Posted Bank Deposit", PostedBankDepositHeader); // Reads Instance A's (empty) variableSuggested Fix
After raising OnAfterBankDepositPost, copy the posted header record from Instance B back to Instance A before calling Page.Run:
OnAfterBankDepositPost(BankDepositHeader, BankDepositPost.GetPostedBankDepositHeader(), ShowDialog);
PostedBankDepositHeader := BankDepositPost.GetPostedBankDepositHeader();
if ShowDialog then
Page.Run(Page::"Posted Bank Deposit", PostedBankDepositHeader);Or alternatively, pass BankDepositPost.GetPostedBankDepositHeader() directly to Page.Run.
Workaround
Subscribe to OnAfterBankDepositPost, set ShowDialog := false to suppress the broken navigation, and call Page.Run with the correctly-populated PostedBankDepositHeader from the event parameter:
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Bank Deposit-Post", 'OnAfterBankDepositPost', '', false, false)]
local procedure FixPostedBankDepositNavigation(BankDepositHeader: Record "Bank Deposit Header"; var PostedBankDepositHeader: Record "Posted Bank Deposit Header"; var ShowDialog: Boolean)
begin
if not ShowDialog then
exit;
ShowDialog := false;
Page.Run(Page::"Posted Bank Deposit", PostedBankDepositHeader);
end;Versions
- Business Central 27.5 (on-premises), runtime 16.0
- Bank Deposits extension version 27.5.46862.0
- Also confirmed present on
mainbranch (v29.0)