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

(4) ShareShare
ReportReport
Posted on by 12

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,826 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;
    }
     
  • ChanakaJinasena Profile Picture
    12 on at
    Print Customer Payment Receipt on Cash Receipt Journal Post
    Hi Nimrasa,
     
    Thanks for the update. However, cust ledger entry stll isn't returning any reocrds. I'm not sure if I'm using the correct event (OnAfterPostGenJnlLine) for Evntsubscriber. Any thoughts?
     
    Regards,
    Chanaka
  • Suggested answer
    OussamaSabbouh Profile Picture
    2,190 on at
    Print Customer Payment Receipt on Cash Receipt Journal Post
    Hello,
    Can you try this:

    if CustLedgerEntry.FindFirst() then begin
    // Set the view on the report and run it (This is the fix)
    PaymentReceiptReport.SetTableView(CustLedgerEntry);
    PaymentReceiptReport.RunModal();
    end else
    // Inform the user if the related ledger entry could not be found.
    Message(CouldNotFindCLEDsg, GenJournalLine."Document No.");
  • CU20051014-1 Profile Picture
    on at
    Print Customer Payment Receipt on Cash Receipt Journal Post
    That’s a great approach to enhancing the posting workflow by integrating the Customer Payment Receipt directly into the cash receipt journal process. Ensuring that Report 211 opens with the correct Customer Ledger Entry filter is key to streamlining post-transaction documentation and improving user efficiency. It might help to double-check the `SetRange` or `SetFilter` logic in your code to ensure the correct entry is passed before calling the report. For a smoother implementation and to explore related customization examples, I recommend visiting the Microsoft Dynamics 365 Business Central documentation portal or installing the AL Language extension for Visual Studio Code to debug and refine your code effectively.
  • CU20051014-1 Profile Picture
    on at
    Print Customer Payment Receipt on Cash Receipt Journal Post
    This is a great approach to improving the posting workflow for cash receipt journals by adding a direct prompt to print the Customer Payment Receipt (Report 211). Ensuring the filter correctly targets the related Customer Ledger Entry is key—reviewing the “OnAfterPost” or “OnBeforePost” triggers and verifying that the correct entry number is passed into the report parameters often resolves such issues. For a smoother experience and better code validation, I recommend using the AL Language Extension in Visual Studio Code or visiting Microsoft Learn for detailed Business Central development examples and best practices.
  • ChanakaJinasena Profile Picture
    12 on at
    Print Customer Payment Receipt on Cash Receipt Journal Post
    Hi OussamSabbouh,
     
    Thaks for the suggestion. 
     
    The problem is that the Cust. Ledger Entry is not filtering correctly, causing the program to exit on .FindFirst
     
    Regards,

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,351

#2
Sumit Singh Profile Picture

Sumit Singh 2,072

#3
YUN ZHU Profile Picture

YUN ZHU 1,807 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans