Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Under review by Community Managers

Under review

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

How to write a query based on report with a dataitem to run the report fastly

Posted on by 6
Hi All,
           I created a custom report with bank ledger entries, here my dataitem is bank account ledger entry, i had grouping on shortcutdimension, 6, 7, and country region code, for one  getting amount in lcy with setrange of 0Days to end date in the report, for another column i am using the query object to get the amounlcy values from setranging with  start date to end date given in the request page, but my report is running for 20 minutes with these details, total is also coming wrongly. how can we reduce the generating time of the report. I am attaching the code, and below can anyone help me on this, i am new to reports and queries.
 
 dataset
    {
        dataitem(/Bank Account Ledger Entry/; /Bank Account Ledger Entry/)
        {
            column(Bank_Account_No_; /Bank Account No./) { }
            column(Amount__LCY_; /Amount (LCY)/) { }
            column(CountryName; CountryName) { }
            column(Sectors; /Shortcut Dimension 7 Code/) { }
            column(Categorycode; /Shortcut Dimension 6 Code/) { }
            dataitem(Integer; Integer)
            {
                column(TotalBALE; TotalBALE) { }
                column(FinalBALE; FinalBALE) { }
                trigger OnPreDataItem()
                begin
                    SetRange(Number, 1);
                    CreditActivity.SetRange(CreditActivity.PostingDateFilter, StartDate, EndDate);
                    CreditActivity.SetRange(CreditActivity.ShortcutDimension6Code, /Bank Account Ledger Entry/./Shortcut Dimension 6 Code/);
                    CreditActivity.SetRange(CreditActivity.ShortcutDimension7Code, /Bank Account Ledger Entry/./Shortcut Dimension 7 Code/);
                    CreditActivity.SetRange(CreditActivity.CountryRegionCode, /Bank Account Ledger Entry/./Country/Region Code/);
                    CreditActivity.Open();
 
                    CreditActivity1.SetRange(CreditActivity1.PostingDateFilter, StartDate, EndDate);
                    CreditActivity1.Open();
                end;
 
                trigger OnAfterGetRecord()
                begin
                    if CreditActivity.Read() then begin
                        TotalBALE := CreditActivity.AmountLCY;
                    end
                    else begin
                        CurrReport.Skip();
                    end;
                    if CreditActivity1.Read() then
                        FinalBALE := CreditActivity1.AmountLCY
                    else
                        CurrReport.skip();
                end;
            }
            trigger OnPreDataItem()
            begin
                SetRange(/Posting Date/, 0D, EndDate);
 
            end;
 
            trigger OnAfterGetRecord()
            begin
                Clear(CountryName);
                CountryRegion.Reset();
                if CountryRegion.Get(/Country/Region Code/) then
                    CountryName := CountryRegion.Name;

            end;
        }
  requestpage
    {
        layout
        {
            area(content)
            {
                group(Dates)
                {
                    field(StartDate; StartDate)
                    {
                        Caption = 'Start Date';
                        ApplicationArea = All;
                    }
                    field(EndDate; EndDate)
                    {
                        Caption = 'End Date';
                        ApplicationArea = All;
                    }
 
                }
            }
        }
        actions
        {
            area(processing)
            {
 
            }
        }
    }
    trigger OnPreReport()
    begin
        if StartDate = 0D then
            Error('Start Date must have a value');
        if EndDate = 0D then
            Error('End Date must have a Value');
        if EndDate < StartDate then
            Error('End Date must not be greater than Start Date');
        NullValue := '';
 
    end;
 
    var
        StartDate: Date;
        EndDate: Date;
 
        CountryRegion: Record /Country/Region/;
        CountryName: TExt[100];
 
 
 
Thanks Sarath.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans