How to avoid GETRANGEMIN run-time error

Eugene
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
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
0
Comments
-
What error do you get?
I do not remember this funtion to give a runtime error unlessFROM 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.0 -
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.com0 -
Hej David,
as far as I know, there is no way of avoiding an error there ](*,)
Havingsetfilter("Date Filter",'..%1',310306d); message('%1',getrangemin("Date Filter"));
you get the messageThe filter '..31-03-06' on the Date Filter field ... should specify a minimum value.
Of couse you may use the GETVIEW, and analyse if there is a rangemin Date Filter ...With Kind Regards
Thoms Hviid Thorn0 -
Yes, that is what the helpfile says. You'll have to evaluate the filter in order to see if it is valid for GETRANGEMIN.0
-
Thomas Hviid Thorn wrote:Hej David,
as far as I know, there is no way of avoiding an error there ](*,)
Havingsetfilter("Date Filter",'..%1',310306d); message('%1',getrangemin("Date Filter"));
you get the messageThe filter '..31-03-06' on the Date Filter field ... should specify a minimum value.
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.com0 -
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 Thorn0 -
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.com0 -
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
Peter0 -
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 helps0 -
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
Peter0 -
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.
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 FilterAnalyst 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.com0 -
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.
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
Peter0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions