Skip to main content

Notifications

Announcements

No record found.

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
  • Suggested answer
    Shathika Karunaratne Profile Picture
    on at
    RE: Report Developement
    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;
    }
  • Suggested answer
    Andy Sather Profile Picture
    on at
    RE: Report Developement

    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.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

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

#1
YUN ZHU Profile Picture

YUN ZHU 446 Super User 2025 Season 1

#2
Sagar Dangar, MCP Profile Picture

Sagar Dangar, MCP 347

#3
Mansi Soni Profile Picture

Mansi Soni 327

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans