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

Community site session details

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

Daily Order Report - Date Issue

(4) ShareShare
ReportReport
Posted on by 533
I am attempting to create an RDL report that shows Sales Orders entered for a given date.  Below is the code.  What is happening is that no matter which Date is used to filter on the Order Date, the first Sales Order record in the list always appears.  For example, the first Sales Order record has an Order Date of 2/3/2025, and if I enter a Date in the report for 2/28/2025, that first record appears along with the correctly dated orders.
 
If I enter a date with no Sales Orders, that same order appears in the report.
 
What am I missing in the code below?
 
If I use the RequestFilterFields (commented out below), it works, but then I am not sure how to provide the filter with a default date value (which I would want to have).  I prefer the Date option in the RequestPage because it allows the date to be picked from a Calendar, but I need to be able to only include the Orders with the correct date.
 
report 50101 "Daily Order Log"
{
    ApplicationArea = All;
    Caption = 'Daily Order Log Report';
    UsageCategory = ReportsAndAnalysis;
    DefaultRenderingLayout = DailyOrderLog;
    dataset
    {
        dataitem(SH; "Sales Header")
        {
            DataItemTableView = where("Document Type" = FILTER('Order'));
            // RequestFilterFields = "Order Date";
            column(OrderDate; "Order Date")
            {
            }
            column(No; "No.")
            {
            }
            column(MasterNo; "Master No.")
            {
            }
            column(BilltoCustomerNo; "Bill-to Customer No.")
            {
            }
            column(ExternalDocumentNo; "External Document No.")
            {
            }
            column(BilltoName; "Bill-to Name")
            {
            }
            column(SalespersonCode; "Salesperson Code")
            {
            }
            column(ShiptoAddress; "Ship-to Address")
            {
            }
            column(ShiptoCity; "Ship-to City")
            {
            }
            column(ShiptoState; "Ship-to County")
            {
            }
            dataitem(SL; "Sales Line")
            {
                DataItemLink = "Document Type" = field("Document Type"),
                             "Document No." = field("No.");
                DataItemTableView = where("Quantity" = FILTER(> 1), "Type" = FILTER("Item"));
                column(ItemDescription; Description)
                {
                }
                column(UnitPrice; "Unit Price")
                {
                }
                column(Qty; Quantity)
                {
                }
                column(ExtPrice; Amount)
                {
                }
                trigger OnPreDataItem()
                begin
                    SH.SetRange("Order Date", OrderDate, OrderDate);
                    // SH.SetFilter("Order Date", '%1', OrderDate);
                end;
            }
        }
    }
    requestpage
    {
        layout
        {
            area(Content)
            {
                group(Options)
                {
                    Caption = 'Options';
                    field(OrderDate; OrderDate)
                    {
                        ApplicationArea = Basic, Suite;
                        Caption = 'Order Date';
                        ToolTip = 'Specifies the Order Date that you want the Orders printed.';
                    }
                }
            }
        }
        actions
        {
            area(Processing)
            {
            }
        }
        trigger OnOpenPage()
        begin
            // if OrderDate = 0D then
            OrderDate := Today();
        end;
    }
    rendering
    {
        layout(DailyOrderLog)
        {
            Type = RDLC;
            LayoutFile = 'DailyOrderLog.rdl';
        }
    }
    var
        OrderDate: date;
}
 
I have the same question (0)
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    19,137 Super User 2025 Season 2 on at
    Daily Order Report - Date Issue
    Try this
    trigger OnPreDataItem()
    begin
        SetRange("Order Date", OrderDate, OrderDate);
    end;
  • Verified answer
    ME-31032107-0 Profile Picture
    533 on at
    Daily Order Report - Date Issue
    I figured it out, sometimes you just need to step away and look with a fresh set of eyes.  Turns out I had the OnPreDataItem trigger within the linked Sales Line table, instead of outside the }.  So simple.....
     
    So instead of:
                    column(ExtPrice; Amount)
                    {
                    }
                    trigger OnPreDataItem()
                    begin
                        SH.SetRange("Order Date", OrderDate, OrderDate);
                        // SH.SetFilter("Order Date", '%1', OrderDate);
                    end;
                }
     
    It needed to be:
                    column(ExtPrice; Amount)
                    {
                    }
                }
                    trigger OnPreDataItem()
                    begin
                        SH.SetRange("Order Date", OrderDate, OrderDate);
                        // SH.SetFilter("Order Date", '%1', OrderDate);
                    end;
  • ME-31032107-0 Profile Picture
    533 on at
    Daily Order Report - Date Issue
    , that is what I originally had, and it still includes the first Sales Order in the Order List, with an Order Date that does not match the Date filter.  Neither SetRange nor SetFilter are working correctly.  If I am able to figure out why the first Sales Order record is getting included, then it will work.
  • ME-31032107-0 Profile Picture
    533 on at
    Daily Order Report - Date Issue
    , moving SetRange to the OnPreReport trigger does not perform any data filtering at all.  The entire list of Sales Orders appear in the report.
  • Suggested answer
    KP - Solution Architect Technical Profile Picture
    652 on at
    Daily Order Report - Date Issue
    Hi
     
    You can try the below OnPreDataitem, it works perfectly
     
     
    Let me know if this helped you.
     
    Thanks,
    KP
  • Suggested answer
    YUN ZHU Profile Picture
    92,206 Super User 2025 Season 2 on at
    Daily Order Report - Date Issue
    Hi, try moving the filter to trigger OnPreReport() first.
     
    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 4,197

#2
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 3,673

#3
Sumit Singh Profile Picture

Sumit Singh 2,907

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans