Options

SETRANGE with Datefilter

HenryHenry Member Posts: 18
edited 2002-12-11 in Navision Financials
Hello,

In the SETRANGE in the code of an ITEM report i would like to use the values of the datefilter. Does anybody know how i can solve this problem? For example:

Item.SETRANGE(Datefilter,X);

In this case is X the value the user enters in the field Datefilter when he tries to run the report. I've tried to make a variable of it (X := Item.GETFILTER(Datefilter);) but this one doesn't work because of typeconversion text/date or date/text.

Thank you for thoughts.

Greetzz,
Henry

Comments

  • Options
    HenryHenry Member Posts: 18
    Thanks to Paul Baxter, the following solution:

    Hi Henry


    GETFILTER returns a text variable which contains the filter set on the field this could be "..01/01/02|01/02/02..28/02/02|01/06/02.." or something like that using English dates (that’s the month and date reversed for the yanks).
    What you need to use are the functions GETRANGEMIN and GETRANGEMAX, which return the bottom and top of the range respectively.
    Be warned the variable has to be filtered by a range or else a run time error will occur.


    Paul Baxter
  • Options
    knightknight Member Posts: 45
    Hey Henry,

    I would just like to add a different suggestion. The use of GETRANGEMIN and GETRANGEMAX is only useful if a simple date range is entered by a user eg "01/01/02..01/02/02"... however using a filter such as this
    "..01/01/02|01/02/02..28/02/02|01/06/02.." would make those commands useless..

    You were on the right track initially... making a Text variable such as vDateFilter, and then writing in code vDateFilter := Rec.GETFILTER(Date); (Rec being whatever the DataItem table name is)

    Once you have this filter in a text variable, instead of doing Item.SETRANGE("Date Filter",vDateFilter); you must use SETFILTER instead..
    Item.SETFILTER("Date Filter",vDateFilter);

    I'll explain the difference.. when you use SETRANGE, Navision thinks you are setting a range on a singular value of the data type of that particular field.. eg. When you do SETRANGE on a Date Field, the value you are setting the range on, must also be of type Date.

    If you use SETFILTER, it will accept anything you try and filter on, as long as it has been formatted to Text. Eg. on a Date field, you would specify a Date written as text (eg. '010102' not 010102D).

    The reason it was falling over for you previously, was that you were using Item.GETFILTER("Field name") which will return a Text, and then useing SETRANGE on a Date field with a Text. Hence, the conversion error.

    Sorry for the long explanation, but hope it helps.
    Henry wrote:
    Thanks to Paul Baxter, the following solution:

    Hi Henry


    GETFILTER returns a text variable which contains the filter set on the field this could be "..01/01/02|01/02/02..28/02/02|01/06/02.." or something like that using English dates (that’s the month and date reversed for the yanks).
    What you need to use are the functions GETRANGEMIN and GETRANGEMAX, which return the bottom and top of the range respectively.
    Be warned the variable has to be filtered by a range or else a run time error will occur.


    Paul Baxter
  • Options
    HenryHenry Member Posts: 18
    Thanks Knight,
    This one works well. Such tips you gave makes this forum very usefull!
    Greetings,
    Henry
Sign In or Register to comment.