Skip to main content

Notifications

Announcements

No record found.

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

How to date range in Business Central

Posted on by 200

I have two fields DatecreateTo and DatecreateFrom which is getting from systemcreatedat so when I need range between yesterday and today it's showing only for today, ? 

Please is there any solution how we can do,

I used setfilter  on both fields and passed the variable to it which I globally defined., And hence called.

  • Suggested answer
    Govinda Kumar Profile Picture
    Govinda Kumar 2,203 Super User 2024 Season 1 on at
    RE: How to date range in Business Central

    Hi,

    I'm not sure if your code meets your requirements, but it seems that you have defined the same field (recEnquiries.DateCreated) twice, which could be causing the issue you are facing. Try adding recEnquiries.DateCreatedTo instead.. like this

    varFilterPageBuilder.AddField('Enquiries', recEnquiries.DateCreated);

    varFilterPageBuilder.AddField('Enquiries', recEnquiries.DateCreatedTo);

    Regards

  • Dividutt Profile Picture
    Dividutt 200 on at
    RE: How to date range in Business Central

    date-is-created-and-to.png

    This is code:

                action("Open Enquiries Filter Page")

                {

                    Caption = 'Open Enquiries Filter Page';

                    ApplicationArea = All;

                    Promoted = true;

                    PromotedCategory = Process;

                    PromotedIsBig = true;

                    trigger OnAction()

                    var

                        varFilterPageBuilder: FilterPageBuilder;

                        Enquiries: Record Enquiries;

                        FilterExpr: text;

                        recEnquiries: Record Enquiries;

                        Past3Months: Date;

                        varDefaultView: Text;

                        varDateItem: Text[30];

                        cdu_FilterTokens: Codeunit "Filter Tokens";

                    begin

                        Enquiries.Reset();

                        varFilterPageBuilder.AddTable('Enquiries', Database::Enquiries);

                        varFilterPageBuilder.AddField('Enquiries', Rec.No);

                        varFilterPageBuilder.AddField('Enquiries', Rec.Status);

                        varFilterPageBuilder.AddField('Enquiries', Rec.Email);

                        varFilterPageBuilder.AddField('Enquiries', Rec.Contact);

                        varFilterPageBuilder.AddField('Enquiries', recEnquiries.DateCreated);

                        varFilterPageBuilder.AddField('Enquiries', recEnquiries.DateCreated);

                        varFilterPageBuilder.PageCaption := 'Enquiries Filter Page';

                        if varFilterPageBuilder.RunModal() then begin

                            Enquiries.SetFilter(DateCreated, DateCreate);

                            Enquiries.SetFilter(DateCreatedTo, DateCreateTo);

                            if Enquiries.FindSet() then begin

                                Enquiries.SetView(varFilterPageBuilder.GetView('Enquiries'));

                                CurrPage.SetTableView(Enquiries);

                             

                            end;

                        end;

                    end;

                }

            }

        }

        var

            DateCreate: Text;

            DateCreateTo: Text;

    }

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans