Skip to main content

Notifications

Small and medium business | Business Central, N...
Suggested answer

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

Posted on by 6
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;
 
 
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 73,472 Super User 2024 Season 2 on at
    In a custom report how can we use a query object to get some data
    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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans