Skip to main content

Notifications

Small and medium business | Business Central, N...
Answered

Date range function in buisness central

Posted on by 200

I want to use date range function in my page, tried filter tokens but not getting proper date of that range I set,

date-created.png

I tried this code, but something is missing please help in this...

action("Open Enquiries Filter Page")

            {

                Caption = 'Open Enquiries Filter Page';

                ApplicationArea = All;

                Promoted = true;

                PromotedCategory = Process;

                PromotedIsBig = true;

                trigger OnAction()

                var

                    FilterPageBuilder: FilterPageBuilder;

                    Enquiries: Record Enquiries;

                    FilterExpr: text;

                    recEnquiries: Record Enquiries;

                    Past3Months: Date;

                    varDefaultView: Text;

                    varDateItem: Text[30];

                begin

                    // Enquiries.Reset();

                    varDateItem := 'Date record';

                    Enquiries.SetFilter(DateCreated, '');

                    Enquiries.SetFilter(DateCreated, DateCreate);

                    if Enquiries.FindSet() then

                        CurrPage.SetTableView(Enquiries);

                    varDefaultView := Enquiries.GetView;

                    FilterPageBuilder.AddTable(varDateItem, Database::Enquiries);

                    FilterPageBuilder.SetView(varDateItem, varDefaultView);

                    FilterPageBuilder.RunModal();

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

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

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

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

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

                    FilterPageBuilder.AddField('Enquiries', Rec.DateCreated);

                    FilterPageBuilder.PageCaption := 'Enquiries Filter Page';

                    if FilterPageBuilder.RunModal() then begin

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

                        Page.Run(Page::Enquiries, Enquiries);

                    end;

                end;

            }

        }

    }

Thankyou 

  • Dividutt Profile Picture
    Dividutt 200 on at
    RE: Date range function in buisness central

    Thanks working now , having one doubt, when my page run function is triggered why date is not getting filtered there but?

    But in main page it's getting triggered

  • Verified answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,133 Super User 2024 Season 2 on at
    RE: Date range function in buisness central

    try

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

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

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

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

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

                      FilterPageBuilder.AddField('Enquiries', Rec.DateCreated, format(Rec.DateCreated));

                      FilterPageBuilder.PageCaption := 'Enquiries Filter Page';

                      if FilterPageBuilder.RunModal() then begin

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

                        Page.Run(Page::Enquiries, Enquiries);

                      end;

                  end;

  • Dividutt Profile Picture
    Dividutt 200 on at
    RE: Date range function in buisness central

    I want to be able to display in my page the minimum date i.e. 04/21/23 and the maximum date i.e. 04/24/23

    I used

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

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

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

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

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

                       FilterPageBuilder.AddField('Enquiries', Rec.DateCreated);

                       FilterPageBuilder.PageCaption := 'Enquiries Filter Page';

                       if FilterPageBuilder.RunModal() then begin

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

      StartDate :=Enquiries .GETRANGEMIN("Datecreate");

    EndDate :="Enquiries.GETRANGEMAX("Datecreate");                     Page.Run(Page::Enquiries, Enquiries);

                       end;

                   end;

               }

           }

       }

    I tried this but still getting all the dates, not filtered,is something wrong in code.

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,133 Super User 2024 Season 2 on at
    RE: Date range function in buisness central

    can you please explain your issue with an example and what is the expected result?

  • Dividutt Profile Picture
    Dividutt 200 on at
    RE: Date range function in buisness central

    Not getting filtered getting all dates, where  to use this function.

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,133 Super User 2024 Season 2 on at
    RE: Date range function in buisness central

    Please try GetRangeMin and GetRangeMax

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!

Community AMA December 12th

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

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,056 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans