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 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.
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');
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;
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.
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
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.
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');
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)
Comments
I do not remember this funtion to give a runtime error unless
IF GETFILTER("Date Filter") <> '' THEN
fromDate := GETRANGEMIN("Date Filter");
If you need a filter to be input
IF GETFILTER("Date Filter") = '' THEN
ERROR('Message');
Mobile: +44(0)7854 842801
Email: david.cox@adeptris.com
Twitter: https://twitter.com/Adeptris
Website: http://www.adeptris.com
as far as I know, there is no way of avoiding an error there ](*,)
Having you get the message including the lecture on setting filters.
Of couse you may use the GETVIEW, and analyse if there is a rangemin Date Filter ...
Thoms Hviid Thorn
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');
Mobile: +44(0)7854 842801
Email: david.cox@adeptris.com
Twitter: https://twitter.com/Adeptris
Website: http://www.adeptris.com
- 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! 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).
Thoms Hviid Thorn
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;
Mobile: +44(0)7854 842801
Email: david.cox@adeptris.com
Twitter: https://twitter.com/Adeptris
Website: http://www.adeptris.com
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.
Peter
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
I think it will be close to impossible to de-code all possible situations.
Peter
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
Mobile: +44(0)7854 842801
Email: david.cox@adeptris.com
Twitter: https://twitter.com/Adeptris
Website: http://www.adeptris.com
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)
Peter