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 :
Business Central forum

Date filter

(0) ShareShare
ReportReport
Posted on by 700

Hi All,

In my report request page, I have two filters i.e. Start Date and End Date. I have to display the records from this specified range. Although these filters are working fine but when I skip putting these filters and want to filter the data based on other filters present wrong data is displayed. Could anyone fix it ?

Below is the source code :-

report 50104 EmployeeComments
{
    Caption = 'Comments';
    UsageCategory = ReportsAndAnalysis;
    ApplicationArea = All;
    DefaultLayout = RDLC;
    RDLCLayout = 'EmployeeComments.rdl';

    dataset

    {
        dataitem(Employee1; Employee)
        {
            RequestFilterFields = "No.", "Office Location", "Status";

            PrintOnlyIfDetail = true;

            // DataItemTableView = where ("Table Name" = filter (Employee));

            dataitem("Human Resource Comment Line"; "Human Resource Comment Line")
            {
                DataItemLink = "No." = field ("No.");
                RequestFilterFields = Comment_Type;

                column(FORMAT_TODAY_0_4_; Format(Today, 04))
                {
                }
                column(COMPANYNAME; COMPANYPROPERTY.DisplayName)
                {
                }
                column(CurrReport_PAGENO; CurrReport.PageNo)
                {
                }
                column(No_; "No.")
                {
                }

                column(EmpFirstName; EmpFirstName)
                {
                }

                column(EmpLastName; EmpLastName)
                {
                }

                column(EmpLoc; Employee."Office Location")
                {
                }

                column(Comment_Type; Comment_Type)
                {
                }

                column(Date; format(Date))
                {
                }

                column(Comment; Comment)
                {
                }
                column(NoFilter; NoFilter)
                {
                }
                column(CommentTypeFilter; CommentTypeFilter)
                {
                }
                column(CommentDateFromFilter; CommentDateFromFilter)
                {
                }
                column(EmployeeFilter; EmployeeFilter)
                {
                }
                column(HumanResourceCommentLineFilter; HumanResourceCommentLineFilter)
                {
                }


                // dataitem(Employee; Employee)
                // {
                //     RequestFilterHeading = '';
                //     RequestFilterFields = "Office Location", "Status";
                //     DataItemLinkReference = "Human Resource Comment Line";
                //     DataItemLink = "No." = field ("No.");
                // }

                trigger OnPreDataItem()

                var

                    myInt: Integer;

                begin

                    SetRange(Date, CommentDateFrom, CommentDateTo);
                    EmployeeFilter := Employee1.GetFilters;
                    HumanResourceCommentLineFilter := "Human Resource Comment Line".GetFilters;

                end;

                trigger OnAfterGetRecord()

                begin
                    // IF (CommentDateFrom <> 0D) and (CommentDateTo <> 0D) then begin
                    //     SetRange(Date, CommentDateFrom, CommentDateTo);
                    // end;

                    Clear(EmpFirstName);
                    Clear(EmpLastName);
                    Clear(EmpLoc);
                    if Employee.Get("No."then begin
                        EmpFirstName := Employee."First Name";
                        EmpLastName := Employee."Last Name";
                        EmpLoc := Employee."Office Location";
                    end;
                    //SetRange(Date, CommentDateFrom, CommentDateTo);
                end;
            }
        }
    }
    requestpage

    {

        layout

        {
            area(Content)

            {

                field("Comment Date From"; CommentDateFrom)

                {

                    ApplicationArea = all;
                    ShowMandatory = true;

                    // trigger OnValidate()
                    // var
                    //     myInt: Integer;

                    // begin

                    //     if Format(CommentDateFrom) = ' ' then begin
                    //         Error('Value required');
                    //     end;
                    // end;

                }

                field("Comment Date To"; CommentDateTo)

                {

                    ApplicationArea = all;
                    ShowMandatory = true;

                }

            }

        }

        trigger Onopenpage()                   //sets default value for the Status filter as 'Active'
        var
            myInt: Integer;
        begin
            Employee1.SetRange(Status, Employee1.Status::Active);
        end;

    }
    // trigger OnPreReport()
    // var
    //     myInt: Integer;
    // begin
    //     NoFilter := Employee.GetFilters;
    //     CommentTypeFilter := "Human Resource Comment Line".GetFilters;
    //     CommentDateFromFilter := "Human Resource Comment Line".GetFilters;
    // end;


    var

        CurrReport_PAGENOCaptionLbl: Label 'Page';
        CommentDateFrom: Date;
        CommentDateTo: Date;
        HumanResource: Record "Human Resource Comment Line";
        Employee: Record Employee;
        EmpFirstName: Text;
        EmpLastName: Text;
        EmpLoc: Code[50];
        NoFilter: Text;
        CommentTypeFilter: Text;
        CommentDateFromFilter: Text;
        EmployeeFilter: Text;
        HumanResourceCommentLineFilter: Text;

}

Thanks in advance !
Categories:
  • Suggested answer
    Suresh Kulla Profile Picture
    50,280 Super User 2026 Season 1 on at

    You need to apply the filters in the OnPreDataItem trigger.

  • Dynamics 365 Business Central Profile Picture
    700 on at

    I didn't get you. How can we specify the filters in the OnPreDataItem trigger ?

    What would be the syntax and all ?

  • Dynamics 365 Business Central Profile Picture
    700 on at

    Could you please make necessary modifications in the code I provided ! It would be a great help, sir.

  • Dynamics 365 Business Central Profile Picture
    700 on at

    Hi Suresh,

    Could you please revert back, if possible ! It is needed urgently.

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

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 > Business Central

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans