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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

In a custom report how can we use a query object to get some data

(1) ShareShare
ReportReport
Posted on by
Hi All,
  
          I have created a custom report with dataitem bank account ledger entries, in the request page i had start date and end date, if i try to use a  bank account ledger record variable for getting amount lcy by filtering with startdate, end date, my report is taking to much time, so i used the query object and creating for getting those amount lcy amount but it is not coming accurately, i am attaching my code and the output also, in report grouping is there on shortcut dimension 6,7 and country region code, can anyone help me on this, thanks for your advices.
 dataset
    {
        dataitem(/Bank Account Ledger Entry/; /Bank Account Ledger Entry/)
        {
            UseTemporary = true;
            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/) { }
 
            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;
                bankCount := /Bank Account Ledger Entry/.CountApprox;
 
            end;
        }
 
        dataitem(Integer; Integer)
        {
            column(TotalBALE; TotalBALE) { }
            column(FinalBALE; FinalBALE) { }
            trigger OnPreDataItem()
            begin
                SetRange(Number, 1, bankCount);
                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();

            end;
 
            trigger OnAfterGetRecord()
            begin
                if CreditActivity.Read() then begin
                    TotalBALE := CreditActivity.AmountLCY;
                end
                else begin
                    CurrReport.Skip();
                end;
               
            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');
 
    end;
 
 
I have the same question (0)
  • Suggested answer
    YUN ZHU Profile Picture
    99,974 Super User 2026 Season 1 on at
    Hi, it looks the same as the problem below.
     
     
    Thanks.
    ZHU

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,024 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,145 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 705 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans