SETFILTER - extended functionality?
YuriM
Member Posts: 12
Hi,
i have noticed in some standard forms such type of expressions:
The question is: would it be not the same to write like this?
Please correct me, if I am wrong.
i have noticed in some standard forms such type of expressions:
IF GETFILTER("Filter") <> '' THEN
MatrixRec.SETFILTER(MatrixRec."No.",GETRANGEMIN("Filter"),GETRANGEMAX("Filter"));
It seems that SETFILTER can function in the same way like SETRANGE, only it is probably not documented(?). Examples are in the Forms/Pages 9211, 9213, 9215.The question is: would it be not the same to write like this?
MatrixRec.SETFILTER(MatrixRec."No.",GETFILTER("Filter"));
My guess is, that in the first case '1..10' = '10..1' and in the second case not.Please correct me, if I am wrong.
0
Comments
-
SETRANGE(Field,StartValue,EndValue) is a fancy way of programming SETFILTER(Field,'StartValue..EndValue'), not the other way around. SETRANGE is a parameterized way to do a SETFILTER on a range or single value, so I would say that SETRANGE is an extended version of SETFILTER.
I use SETRANGE as much as possible, I never use SETFILTER if it is a single value or a range.0 -
I agree, but according to the Help, SETFILTER is not supposed to work that way. I mean that expression Rec.SETFILTER("No.",'1','10') is actually wrong. Or do I misunderstand something?Record.SETFILTER(Field, String, [Value],...)
Parameters
Record
Type: Record
The record that contains the field that you want to filter.
Field
Type: Field
The field that you want to filter.
String
Type: Text or code
The filter expression. A valid expression consists of alphanumeric characters and one or more of the following operators: <, >, *, &, |, and =. You can use replacement fields (%1, %2, and so on) to insert values at run-time.
Value
Type: Any
Replacement values to insert in replacement fields in the filter expression. The data type of Value must match the data type of Field.0 -
I never said that that is correct, I don't know how you got that. With the parameters that you are describing you would use SETRANGE, not SETFILTER.YuriM wrote:I mean that expression Rec.SETFILTER("No.",'1','10') is actually wrong. Or do I misunderstand something?
Syntax:
Record.SETFILTER(Field, String, [Value],...)
You have to specify the filter as a string. The value parameters are optional in case you use the value substitution markers. So you could do this:
Record.SETFILTER("No.",'%1..%2','1','10');
The filter string would then end up being "1..10", so that is the same as this:
Record.SETFILTER("No.",'1..10');
Now you can also use SETRANGE for the same purpose. Syntax:
Record.SETRANGE(Field [,FromValue] [.ToValue])
and in your case you'd do this:
Record.SETRANGE("No.",'1','10');
And it would all come down to exactly the same thing.0 -
Hi DenSter,
Please read carefully the first sentence in my first postDenSter wrote:I never said that that is correct, I don't know how you got that.
These bugs (if they are not a new undocumented functionality) are "all over" in the new standard. They are, for example, in the Forms/Pages 9211, 9213, 9215, 9217.
And I have tested it once again - the code works correctly only because of the "bug" in the function GETRANGEMIN. According to Help, it should return a runtime error, if the filter is '1|10', but in reality it returns exactly this string '1|10'. To make it more clear:
Filter := '1..5|10';
Rec.SETFILTER("No.", GETRANGEMIN("Filter"), GETRANGEMAX("Filter"));
results in
Rec.SETFILTER("No.", '1..5|10', '1..5|10');
Since the first parameter has no %1, the second parameter will be ignored.0 -
Hello, YuriM!
There is no bug with functions GETRANGEMIN or GETRANGEMAX.
They work correct. The reason for misunderstanding is ' symbol.
Example.
prerequisite procedures
1. Open form 31
2. Add comand button with code in the trigger onPush: MESSAGE(GETRANGEMIN("Location Filter"));
3. Run this form.
test
1. Open FlowFilter window and specify location filter: Blue|Green
2. Close FlowFilter window and press the added button. You will get an error.
3. Open FlowFilter window and add ' to location filter: 'Blue|Green'
4. Close FlowFilter window and press the added button. The message will be "Blue|Green", not "Blue".
The same effect you saw in form 9211.0 -
Hello, apanko!
Thank you for the explanation, I didn't know those details about GETRANGEMIN/GETRANGEMAX.0 -
You asked about SETRANGE and SETFILTER, which I addressed in my answers. If you had specified in your first post that it was really RANGEMAX/RANGEMIN that you were wondering about I would not have spent any time writing what I did.YuriM wrote:Please read carefully the first sentence in my first post
It looks like you got your answer, so that's good
0 -
Hi DenSter
I hilighted the part YuriM is refering to in his initial post.
It looks realy strange to me also :-k . It must be either a :bug: or an undocumented feature, as YuriM says.YuriM wrote:Hi,
i have noticed in some standard forms such type of expressions:
It seems that SETFILTER can function in the same way like SETRANGE, only it is probably not documented(?). Examples are in the Forms/Pages 9211, 9213, 9215.code wrote:IF GETFILTER("Filter") <> '' THEN
MatrixRec.SETFILTER(MatrixRec."No.",GETRANGEMIN("Filter"),GETRANGEMAX("Filter"));
...
I have not checked it out yet, but according to my understanding, this code usually will reduce the filter range to be equal to the lower bound (GETRANGEMIN) and ignore the upper bound (unless the lower range looks like a filter string or does happen to contain replacement fields, where the upper bound was substituted :shock: :?
I belive, the code really should be (substituting the whole IF statement):COPYFILTER("Filter",MatrixRec."No.");0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions

