SETFILTER - extended functionality?

YuriMYuriM Member Posts: 12
Hi,

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.

Comments

  • DenSterDenSter Member Posts: 8,305
    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.
  • YuriMYuriM Member Posts: 12
    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.
  • DenSterDenSter Member Posts: 8,305
    YuriM wrote:
    I mean that expression Rec.SETFILTER("No.",'1','10') is actually wrong. Or do I misunderstand something?
    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.

    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.
  • YuriMYuriM Member Posts: 12
    Hi DenSter,
    DenSter wrote:
    I never said that that is correct, I don't know how you got that.
    Please read carefully the first sentence in my first post :)
    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.
  • apankoapanko Member Posts: 70
    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.
  • YuriMYuriM Member Posts: 12
    Hello, apanko!

    Thank you for the explanation, I didn't know those details about GETRANGEMIN/GETRANGEMAX.
  • DenSterDenSter Member Posts: 8,305
    YuriM wrote:
    Please read carefully the first sentence in my first post :)
    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.

    It looks like you got your answer, so that's good :mrgreen:
  • vaprogvaprog Member Posts: 1,139
    Hi DenSter

    I hilighted the part YuriM is refering to in his initial post.
    YuriM wrote:
    Hi,

    i have noticed in some standard forms such type of expressions:
    code wrote:
    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.
    ...
    It looks realy strange to me also :-k . It must be either a :bug: or an undocumented feature, as YuriM says.
    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.");
    
Sign In or Register to comment.