Hi Community,
I need to display the Request Page for the Customer Payment Receipt (Report ID 211) when posting the cash receipt journal.
Specifically, when the user posts the journal, a message should appear asking if they want to print Report 211. If the user selects "Yes," the Report 211 Request Page should open, pre-filtered for the relevant Customer Ledger Entry.
[The desired flow is: Post Journal → Message ("Print Report 211?") → Yes → Display Request Page, filtered by the Customer Ledger Entry.]
The issue is that my current code is not filtering the Customer Ledger Entry correctly. Any help would be greatly appreciated.
Thanks!
CustLedgerEntry
record but not actually applying that filter context when passing it to the report. The Report.RunModal
method needs the record to have the proper filters set and needs the record to be positioned correctly.codeunit 50102 "Print Pmt Rcpt On Post CRJ"
{
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Gen. Jnl.-Post Line", 'OnAfterPostGenJnlLine', '', false, false)]
local procedure ShowReceiptReportOnAfterPost(var GenJournalLine: Record "Gen. Journal Line")
var
CustLedgerEntry: Record "Cust. Ledger Entry";
ErrorInfo: ErrorInfo;
PrintReceiptQst: Label 'A customer payment was posted. Do you want to show the Customer Payment Receipt report?';
CouldNotFindCLEDsg: Label 'Could not find the corresponding Customer Ledger Entry for Document No. %1.', Comment = '%1 = Document Number';
ReportExecutionErr: Label 'An error occurred while trying to run the report.';
begin
if GenJournalLine."Journal Template Name" <> 'CASHRCPT' then
exit;
if GenJournalLine."Account Type" <> GenJournalLine."Account Type"::Customer then
exit;
if not Confirm(PrintReceiptQst) then
exit;
CustLedgerEntry.Reset();
CustLedgerEntry.SetCurrentKey("Document No.");
CustLedgerEntry.SetRange("Document No.", GenJournalLine."Document No.");
CustLedgerEntry.SetRange("Customer No.", GenJournalLine."Account No.");
CustLedgerEntry.SetRange("Posting Date", GenJournalLine."Posting Date");
if CustLedgerEntry.FindLast() then begin
if not TryRunReceiptReport(CustLedgerEntry) then begin
ErrorInfo.Title := ReportExecutionErr;
ErrorInfo.Message := GetLastErrorText();
Error(ErrorInfo);
end;
end else
Message(CouldNotFindCLEDsg, GenJournalLine."Document No.");
end;
[TryFunction]
local procedure TryRunReceiptReport(var CustLedgerEntry: Record "Cust. Ledger Entry")
begin
Report.RunModal(Report::"Customer - Payment Receipt", true, false, CustLedgerEntry);
end;
}