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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Filters in OnInit of a list page

(0) ShareShare
ReportReport
Posted on by 18

I created a new list page because I need a special filter (days difference between two fields).

I'm not sure how to do that filter, are there any examples? I haven't found any on the internet...

Say I want all records where Due Date is 7 days or more before Start Date in my Assemble Header (900) list.

*This post is locked for comments

I have the same question (0)
  • Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    Records of what table?

    The filter is something like: SETFILTER(DueDate,'>=%1',CALCDATE('+7D',AssembleHeader."Start Date");

  • SamCha Profile Picture
    18 on at

    Hi Stefano, both fields are in the same table, Assembly Header (900)

    My list page contains a list of Assembly Headers, but I want to filter only those that are late.

    I am looking for a filter I could use in the OnInit to filter the list of records that are about to show in the list page.

  • Verified answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    In OnOpenPage trigger you can set a filter like:

    SETFILTER(DueDate,'>=%1',CALCDATE('+7D',"Start Date"));

  • SamCha Profile Picture
    18 on at

    It tells me DueDate is undefined

  • Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    What is the name of your date field that you want to filter? Is it not called DueDate?

    The suggested filter filters the field called "DueDate" for values >= of Start Date + 7 days.

    Correct the name of the fields with your correct field name and it should work.

  • SamCha Profile Picture
    18 on at

    Thank you Stefano, It's the basic NAV table, so it's "Due Date".

    Now my problem is that sometimes the start date is empty, so I can't do the difference calculation (says invalid date 0D).

    How do I exclude those as well?

  • Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    First apply the filter for Start Date:

    SETFILTER("Start Date",'<>0D');

    Then:

    SETFILTER("Due Date",'>=%1',CALCDATE('+7D',"Start Date"));

  • SamCha Profile Picture
    18 on at

    How do I "apply" the filter?

    I tried to have both lines at the same time in the OnInit but it still gives an error of comparing dates with 0D.

    OnInit()
    
    SETFILTER("Start Date",'<>0D');
    SETFILTER("Due Date",'>=%1',CALCDATE('+7D',"Start Date"));
    


  • Verified answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    Maybe I've understood now your requirements, sorry :)

    Every record has its own Due Date and Start Date fields, and you want only the record where Due Date >= Start Date + 7 days right?

    If so, a simple filter is not enough because the calculation (if due or not) must be done for every record. You can use MARKS.

    Something like:

    SETFILTER("Start Date",'<>0D'); //Remove the empty start date records

    IF FINDSET THEN

    REPEAT

    BEGIN

     IF "Due Date" >= CALCDATE('+7D',"Start Date") THEN

       MARK(TRUE)

     ELSE

       MARK(FALSE);

    END

    UNTIL NEXT=0;

    //Now show only the marked records.

    MARKEDONLY(TRUE);

  • SamCha Profile Picture
    18 on at

    When debugging, it looks like it works for the first record it finds, but the second iteration, the Start date is empty.... and the calcdate errors.

    In the variable list, it looks like the Start date filter is <> today... instead of <> empty date (0D?)

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans