web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

Print Customer Payment Receipt on Cash Receipt Journal Post

(3) ShareShare
ReportReport
Posted on by 2

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.

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
        // run this logic for Customer payments from a Cash Receipt Journal.
        if GenJournalLine."Journal Template Name" <> 'CASHRCPT' then
            exit;
 
        // Ask the user if they want to print the report 211 after posting the journal.
        if not Confirm(PrintReceiptQst) then
            exit;
 
        // Find the Customer Ledger Entry that was just created.
        CustLedgerEntry.SetRange("Document No.", GenJournalLine."Document No.");
        if CustLedgerEntry.FindFirst() then begin
 
            // run the report
            if not TryRunReceiptReport(CustLedgerEntry) then begin
 
                ErrorInfo.Title := ReportExecutionErr;
                ErrorInfo.Message := GetLastErrorText();
                Error(ErrorInfo);
            end;
 
        end else
            // inform the user if the related ledger entry could not be found.
            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;
}

Thanks!

I have the same question (0)
  • Suggested answer
    Nimsara Jayathilaka. Profile Picture
    4,457 on at
    Print Customer Payment Receipt on Cash Receipt Journal Post
    Hi Chanaka
     
    The problem is that you're setting a filter on the 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.
     
    Try This way
     
    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;
    }
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 4,197

#2
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 3,673

#3
Sumit Singh Profile Picture

Sumit Singh 2,907

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans