Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Date Filter

(0) ShareShare
ReportReport
Posted on by 3,061

Hi

  I have 2 dates Start From & End Date . I want if they are not blank , it should be checked that End Date >= Start Date.

Secondly if Dates are not blank then SetRange should be done on Posting Date.

Thanks

*This post is locked for comments

  • Suggested answer
    Yogesh Kulkarni_ Profile Picture
    Yogesh Kulkarni_ 1,762 on at
    RE: Date Filter

    You can write something like:

    IF (StartDate <> 0D) and (EndDate <> 0D) THEN BEGIN

    IF (EndDate >= StartDate) then

    Record.SETRANGE("Posting Date", StartDate, EndDate)

    ELSE

    ERROR('End Date must be greater than Start Date');

    END;

     

    -Yogesh Kulkarni
    Please verify, if you find answer helpful.

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 44,656 on at
    RE: Date Filter

    Could you please let us know what you have tried till now, we will help you to provide a solution if you are running into an issue and that will help you to learn, if you expect us to write the solution for you then you many not learn it.

  • Verified answer
    Marcellus Profile Picture
    Marcellus 2,735 on at
    RE: Date Filter

    Hi Jsshivalik,

    Are you developing a report?

    You can check Report 116, there is a function there called VerifyDates which is similar. They invoke it on Customer - OnPreDataItem but I think it could be better if the users would receive an error when they enter the dates.

    You can create a function like this to check the dates:

    LOCAL CheckDates()
    IF (StartDate = 0D) OR (EndDate = 0D) THEN
      EXIT;
    
    IF StartDate > EndDate THEN
      ERROR('Start Date: %1 is greater than End Date: %2', StartDate, EndDate);

    Create two global variables for the dates and add them to the request page as fields, then you can use the OnValidate trigger for the fields to call your method.

    Let's say your data item is Sales Invoice Headers, on the Sales Invoice Header - OnPreDataItem() you can do this for example:

    IF (StartDate <> 0D) AND (EndDate <> 0D) THEN
      SETFILTER("Posting Date", '%1..%2', StartDate, EndDate);
    
    IF (StartDate <> 0D) AND (EndDate = 0D) THEN
      SETFILTER("Posting Date", '%1..', StartDate);
    
    IF (StartDate = 0D) AND (EndDate <> 0D) THEN
      SETFILTER("Posting Date", '..%1', EndDate);


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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,430 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans