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

Announcements

News and Announcements icon
Community site session details

Community site session details

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

Report Developement

(0) ShareShare
ReportReport
Posted on by 205

Hi Experts,

I am Trying to develop a Report Here.

The Requirement is 

CustNo                       CustName           InvoiceValue                 CreditNoteValue 

Depends upon the Filtering on the Posting Date , The Report Should Give me the Consolidates Stats For the Customers.

I have written some Code But its Not Giving me the Exact Result. What am i Doing Wrong?

eport 50131 MyReport
{
    UsageCategory = ReportsAndAnalysis;
    ApplicationArea = All;
    DefaultLayout = RDLC;
    RDLCLayout = './SR2.rdl';

    dataset
    {
        dataitem(Customer; Customer)
        {
            DataItemTableView = sorting("No.");

            PrintOnlyIfDetail = true;

            column(Name; Name)
            {

            }
            column(No_; "No.")
            {

            }


            column(CreditAmount; CreditAmount)
            {

            }
            column(SalesAmount; SalesAmount)
            {

            }

            dataitem("Cust. Ledger Entry"; "Cust. Ledger Entry")
            {
                DataItemLink = "Customer No." = field("No.");
                column(Debit_Amount__LCY_; "Debit Amount (LCY)")
                {

                }
                column(Credit_Amount__LCY_; "Credit Amount (LCY)")
                {

                }
                trigger OnAfterGetRecord()
                begin


                    "Cust. Ledger Entry"."Debit Amount (LCY)" := 0;
                    "Cust. Ledger Entry"."Credit Amount (LCY)" := 0;

                    "Cust. Ledger Entry".Reset();
                    "Cust. Ledger Entry".SetFilter("Document Type", '%1|%2', "Cust. Ledger Entry"."Document Type"::invoice, "Cust. Ledger Entry"."Document Type"::"Credit Memo");
                    "Cust. Ledger Entry".SetRange("Cust. Ledger Entry"."Posting Date", FromDates, ToDate);
                    "Cust. Ledger Entry".SetRange("Cust. Ledger Entry"."Customer No.", Customer."No.");

                    if "Cust. Ledger Entry".FindSet() then begin
                        repeat
                            "Cust. Ledger Entry".CalcFields("Debit Amount (LCY)","Credit Amount (LCY)");
                            "Cust. Ledger Entry"."Debit Amount (LCY)" := "Cust. Ledger Entry"."Debit Amount (LCY)" + "Cust. Ledger Entry"."Debit Amount (LCY)";
                            "Cust. Ledger Entry"."Credit Amount (LCY)" := "Cust. Ledger Entry"."Credit Amount (LCY)" + "Cust. Ledger Entry"."Credit Amount (LCY)";
                        until "Cust. Ledger Entry".Next = 0;
                    end;



                    //
                end;


            }

           


        }







    }

    requestpage
    {
        layout
        {
            area(Content)
            {
                group(GroupName)
                {
                    field("From Date"; FromDates)
                    {
                        ApplicationArea = All;
                    }
                    field("To Date"; ToDate)
                    {
                        ApplicationArea = All;
                    }
                }
            }
        }

    }

    var
        cust1: Record "Cust. Ledger Entry";
        cust2: Record "Cust. Ledger Entry";

        SalesAmount: Decimal;
        CreditAmount: Decimal;
        FromDates: Date;
        ToDate: Date;
}
Thanks You
I have the same question (0)
  • Suggested answer
    Andy Sather Profile Picture
    Microsoft Employee on at

    Hello  - We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    I will open this up to the community in case they have something to add.

  • Suggested answer
    Shathika Karunaratne Profile Picture
    6 on at
    Please kindly use below code lines. 

    Report
    50131 MyReport
    {
        UsageCategory = ReportsAndAnalysis;
        ApplicationArea = All;
        DefaultLayout = RDLC;
        RDLCLayout = './SR2.rdl';

        dataset
        {
            dataitem(Customer; Customer)
            {
                DataItemTableView = sorting("No.");

                PrintOnlyIfDetail = true;

                column(Name; Name)
                {

                }
                column(No_; "No.")
                {

                }
                column(CreditAmount; CreditAmount)
                {

                }
                column(SalesAmount; SalesAmount)
                {

                }
                trigger OnAfterGetRecord()
                var
                    CustLedgerEntry: Record "Cust. Ledger Entry";
                begin
                    SalesAmount := 0;
                    CreditAmount := 0;
                    CustLedgerEntry.Reset();
                    CustLedgerEntry.SetFilter("Document Type", '%1|%2', CustLedgerEntry."Document Type"::Invoice, CustLedgerEntry."Document Type"::"Credit Memo");
                    CustLedgerEntry.SetRange(CustLedgerEntry."Posting Date", FromDates, ToDate);
                    CustLedgerEntry.SetRange(CustLedgerEntry."Customer No.", Customer."No.");
                    if CustLedgerEntry.FindSet() then begin
                        repeat
                            CustLedgerEntry.CalcFields("Debit Amount (LCY)", "Credit Amount (LCY)");
                            SalesAmount += CustLedgerEntry."Debit Amount (LCY)";
                            CreditAmount += CustLedgerEntry."Credit Amount (LCY)";
                        until CustLedgerEntry.Next = 0;
                    end;
                end;
            }
        }

        requestpage
        {
            layout
            {
                area(Content)
                {
                    group(GroupName)
                    {
                        field("From Date"; FromDates)
                        {
                            ApplicationArea = All;
                        }
                        field("To Date"; ToDate)
                        {
                            ApplicationArea = All;
                        }
                    }
                }
            }

        }

        var
            SalesAmount: Decimal;
            CreditAmount: Decimal;
            FromDates: Date;
            ToDate: Date;
    }

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,496 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 961 Super User 2026 Season 1

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 870 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans