Filter include

dulaman
dulaman Member Posts: 73
Hi all,

This should be an easy one. My head is buzzing and my eyes are rolling but I am so tired to find out the trick for this simple idea:

I need a filter to get all the dates that are equal or inferior than an given one OR all the dates that are equal or superior than the input.

It should be something like this:

SETFILTER("Starting Date", '>=%1|%2', myDate, 0D);
SETFILTER("Ending Date", '<=%1|%2', myDate, 0D);

But this pair of lines are not OR-ing but AND-ing!!
(excuse my --ehm-- neologisms) :)

What can I do??
-- dulaman
"I don't want to believe. I want to know." (Carl Sagan)

Answers

  • dlauwers
    dlauwers Member Posts: 127
    Setfilter lines always AND, you need to use mark to mark the records. Try and find Mark, MarkOnly on this forum and you will find some examples on how to OR things for different fields.

    Another is to use an extra field with the result of your calculation and filter on this extra flag.

    Hope this helps
    Danny
  • dulaman
    dulaman Member Posts: 73
    Thank you Danny. I'm now trying something like this:
    IF FIND('-') THEN
      REPEAT
        IF "Starting Date" >= myDate THEN MARK(TRUE);
        IF "Ending Date" <= myDate THEN MARK(TRUE);
      UNTIL NEXT = 0;
    MARKEDONLY(TRUE);
    

    But it's not working at all. My report seems to fully ignore this piece of code! :roll:
    -- dulaman
    "I don't want to believe. I want to know." (Carl Sagan)
  • kine
    kine Member Posts: 12,562
    1) Where are you using this code?
    2) Do not forget to 0D date
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • dlauwers
    dlauwers Member Posts: 127
    Dulaman,

    If you are using this in a report, I think that you best use CurrReport.SKIP in the OnAfterGetRecord to skip that record.

    Please it in an if for your condition.

    I don't know if the MARK procedure works inside a report ? #-o

    Danny
  • dulaman
    dulaman Member Posts: 73
    Hi kine

    1) I'm using this code in a kinda "machine table" of my own. The machines start their use in a Starting Date and finish in a Ending Date. Now I need a report that tells me if in a given date that machine has been used. Of course if I enter, let's say, February 14th as myDate, but that machine started its use on 13th and finished on 16th, it should be included in my report as well. It should be included too those machines that have a Starting Date but not an Ending Date yet.

    2) Oops! You are right!
    -- dulaman
    "I don't want to believe. I want to know." (Carl Sagan)
  • kine
    kine Member Posts: 12,562
    I mean in which trigger you entered this C/AL code... in the report in OnPreDataItem or elsewhere?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • dulaman
    dulaman Member Posts: 73
    Yep, on OnPreDataItem.

    Let me recap...

    I want that filter is ON when:

    1) Starting Date = myDate OR
    2) Ending Date = myDate OR
    3) Starting Date < myDate AND Ending Date >= myDate OR
    4) Starting Date < myDate AND Ending Date = 0D

    Hope my purpose is clear now!
    -- dulaman
    "I don't want to believe. I want to know." (Carl Sagan)
  • kine
    kine Member Posts: 12,562
    It means, you want all records which are valid for the date you have in the variable?

    If yes, it is easy... :-)
      SETFILTER("Starting Date",'<=%1|%2',MyDate,0D);
      SETFILTER("Ending Date",'>=%1|%2',MyDate,0D);
    

    It means ("Starting Date" <= MyDate or "Starting Date" = 0D) AND ("Ending Date" >= MyDate or "Ending Date" = 0D) when I assume that "Starting Date<= "Ending Date" if both dates are <>0D.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • dulaman
    dulaman Member Posts: 73
    I KNEW it had to be easy!!

    I was placing the wrong symbolzx%&&AAAGHHH!!! ](*,)

    Thank you very much kine! =D>
    -- dulaman
    "I don't want to believe. I want to know." (Carl Sagan)
  • kine
    kine Member Posts: 12,562
    You are welcome... :-)

    On this example you can see how is important to describe the problem in free text. The free text can tell us much more than some "mathematical" notation 8) (and can solve the problem just because you make clear what you want to do... :wink: )
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.