Options

How to avoid GETRANGEMIN run-time error

EugeneEugene Member Posts: 309
is there a way to avoid GETRANGEMIN generating run-time error ?
i would like to check if a filter is a range N..M and then use N if it is and otherwise do some other processing

Comments

  • Options
    Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    What error do you get?

    I do not remember this funtion to give a runtime error unless
    FROM HELP
    The field you want to find the minimum value for. The current filter on Field can only be a single range filter, otherwise a run-time error occurs.
  • Options
    David_CoxDavid_Cox Member Posts: 509
    Try this test for Value
    IF GETFILTER("Date Filter") <> '' THEN
    fromDate := GETRANGEMIN("Date Filter");

    If you need a filter to be input
    IF GETFILTER("Date Filter") = '' THEN
    ERROR('Message');
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • Options
    Thomas_Hviid_ThornThomas_Hviid_Thorn Member Posts: 92
    Hej David,

    as far as I know, there is no way of avoiding an error there ](*,)

    Having
    setfilter("Date Filter",'..%1',310306d);
    message('%1',getrangemin("Date Filter"));
    
    you get the message
    The filter '..31-03-06' on the Date Filter field ... should specify a minimum value.
    including the lecture on setting filters.

    Of couse you may use the GETVIEW, and analyse if there is a rangemin Date Filter ...
    With Kind Regards
    Thoms Hviid Thorn
  • Options
    Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Yes, that is what the helpfile says. You'll have to evaluate the filter in order to see if it is valid for GETRANGEMIN.
  • Options
    David_CoxDavid_Cox Member Posts: 509
    Hej David,

    as far as I know, there is no way of avoiding an error there ](*,)

    Having
    setfilter("Date Filter",'..%1',310306d);
    message('%1',getrangemin("Date Filter"));
    
    you get the message
    The filter '..31-03-06' on the Date Filter field ... should specify a minimum value.
    including the lecture on setting filters.

    Of couse you may use the GETVIEW, and analyse if there is a rangemin Date Filter ...

    Hi Thomas

    IF GETFILTER("Date Filter") <> '' THEN;

    I use this to aviod the error message as it returns a TRUE or FALSE, so you can then GETRANGEMIN, conditionally as in examples below.

    // If the user has put in a filter then fill myDate
    IF GETFILTER("Date Filter") <> '' THEN
    myDate := GETRANGEMIN("Date Filter")
    ELSE
    MyDate := WORKDATE;

    // If the user has not put in a filter then tell them
    IF GETFILTER("Location Filter") = '' THEN
    ERROR('You must specify a Location filter');
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • Options
    Thomas_Hviid_ThornThomas_Hviid_Thorn Member Posts: 92
    Hej David and Eugene

    - first of all - my reply should have been to Eugene, who posted the question - sorry for that to both of you.

    I changed my sample, and I do still get an error: Please let my known if you can make it right!
    setfilter("Date Filter",'..%1',310306d); 
    if getfilter("Date filter") <> '' then
      mydate := getrangemin("Date Filter");
    message('%1',format(mydate));
    
    the line mydate := getrangemin("Date Filter"); issues the error.

    I tried a year ago in 3.60 and today in 4.00 SP1 (both W1).
    With Kind Regards
    Thoms Hviid Thorn
  • Options
    David_CoxDavid_Cox Member Posts: 509
    Oh right you have no min date, as ..02/02/06, returns a Null 0D.

    In this case you do have a Filter and the only date returnable is the GETRANGEMAX;

    So you can test this

    // To String Value
    IF (GETFITER("Date Filter") <> '')
    AND(COPYSTR(GETFITER("Date Filter"),1,2)<> '..')THEN
    MyDateStr := FORMAT(GETRANGEMIN("Date Filter"))
    ELSE
    MyDateStr := GETFITER("Date Filter");

    // To Date Value have to hard code the Min
    IF (GETFITER("Date Filter") <> '')
    AND(COPYSTR(GETFITER("Date Filter"),1,2)<> '..')THEN
    MyDate := GETRANGEMIN("Date Filter")
    ELSE
    MyDate := 01012000D;
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • Options
    pdjpdj Member Posts: 643
    I see two solutions:
    1) Use the IF CODEUNIT.RUN THEN trick, that hides any errors, but it makes a COMMIT or ROLLBACK, so never use it in a transaction.
    2) Make your own function that sets the filter on the virtual Date table, and then returns the first and last date. However; this only solves it for the Date datatype.
    Regards
    Peter
  • Options
    AlbertvhAlbertvh Member Posts: 516
    you could also try something like this

    IF STRPOS(GETFILTER("Posting Date",'..')) = 1 THEN
    you know that you don't have a minimum range
    ELSE
    IF STRPOS(GETFILTER("Posting Date",'..')) > 1 THEN
    you know you have both minimum and maximum ranges

    Hope this helps
  • Options
    pdjpdj Member Posts: 643
    I think you should be careful with the solutions suggested by David Cox and Albertvh. Datefilters can be made in a lot of ways that makes GETRANGEMIN/MAX fail. I.e. = "0D|01-01-01..02-02-02" and ">01-01-01".
    I think it will be close to impossible to de-code all possible situations.
    Regards
    Peter
  • Options
    David_CoxDavid_Cox Member Posts: 509
    pdj wrote:
    I think you should be careful with the solutions suggested by David Cox and Albertvh. Datefilters can be made in a lot of ways that makes GETRANGEMIN/MAX fail. I.e. = "0D|01-01-01..02-02-02" and ">01-01-01".
    I think it will be close to impossible to de-code all possible situations.
    Ok you have a valid point, and it might happen once in a 1000 runs, but this does not help the original poster.
    So what you can do is use Albertvh solution for the likely scenarios.
    Note: you can get range Min and Max for other data types as well.

    If it is a Date you could just cast the string into your variable or check the length.
    IF STRLEN("Date Filter")<> 18 THEN
    ERROR('Please Enter a date range like 01/01/06..01/31/06');

    IF NOT EVALUATE(fromDate,COPYSTR(GETFILTER("Date Filter"),1,8 ))THEN
    ERROR('Please Enter a date range like 01/01/06..01/31/06');

    Both will work for a Date Filter :)
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • Options
    pdjpdj Member Posts: 643
    David Cox wrote:
    Ok you have a valid point, and it might happen once in a 1000 runs, but this does not help the original poster.
    I read the original post again and have to agree.
    My answer was to the question I imagined was behind the written question: "How do I get the first and last date in any datefilte?" 8)
    Regards
    Peter
Sign In or Register to comment.