Options

Wrong filter from codeunit 46 - GetSelectionFilter

poppinspoppins Member Posts: 647
Hi everyone,

I am using standard codeunit 46 SelectionFilterManagement to extract a filter from a group of records:
I created the following custom functions in my page:

GetSelectionFilterForXXX(VAR recXXX : Record XXX) : Text

recRef.GETTABLE(recXXX );
EXIT(GetSelectionFilter(recRef,recXXX .FIELDNO(FieldXXX)));

GetRecordsXXX(VAR codXXX : Code[20]) : Text

lrecXXX.RESET;
lrecXXX.SETRANGE(Code,codXXX );
EXIT(GetSelectionFilterForXXX(lrecXXX));


GetSelectionFilter is a standard function in codeunit 46.

The problem is that the filter is not correct in some cases :
For example:
When lrecXXX is filtered on the records with the following values for FieldXXX: 1000,1010,1040,6020,6120,9140
The filter is supposed to be : 1000|1010|1040|6020|6120|9140
BUT
this is what I get : 1000|1010|1040|6020|6120..9140

Is there something wrong with my code?
Or this is some kind of bug in the codeunit itself? Has someone experienced this before?

Thanks in advance :)

Answers

  • Options
    vaprogvaprog Member Posts: 1,125
    Hi,
    poppins wrote: »
    Is there something wrong with my code?
    Or this is some kind of bug in the codeunit itself?

    Codeunit 46 has it's shortcomings, but chances are, the filter you get is correct. The filter returned is meant to be used with the current set of values in the table. Whenever two or more adjacent values are encountered, a range is returned in the resulting filter string. When you apply the returned filter string to the record immediately, do you get a different set of records as those you called GetSelectionFilterForXXX with?


    Some of it's flaws:
    • The generic GetSelectionFilter function is not exposed. You have to modify the codeunit for each new recordtype
    • The constructed filter depends on the values currently in the real table.
    • As a result of the above, the codeunit can't cope with temporary tables unless it contains only records copied from the real table.
    • Its quoting is flawed (as of NAV 2013 R2; I never inspected a later version of this codeunit). I once tried to use a better quoting mechanism by using a sequence of SETRANGE ... GETFILTER, only to discover that GETFILTER is not able to quote it's values correctly either. So SETFILTER(GETFLTER) might fail.

    I consider the fact, that it only works for tables with a single primary key field, a limitation, not a flaw, but still, you should be aware of this.
  • Options
    poppinspoppins Member Posts: 647
    vaprog wrote: »
    Hi,
    poppins wrote: »
    Is there something wrong with my code?
    Or this is some kind of bug in the codeunit itself?

    Codeunit 46 has it's shortcomings, but chances are, the filter you get is correct. The filter returned is meant to be used with the current set of values in the table. Whenever two or more adjacent values are encountered, a range is returned in the resulting filter string. When you apply the returned filter string to the record immediately, do you get a different set of records as those you called GetSelectionFilterForXXX with?


    Some of it's flaws:
    • The generic GetSelectionFilter function is not exposed. You have to modify the codeunit for each new recordtype
    • The constructed filter depends on the values currently in the real table.
    • As a result of the above, the codeunit can't cope with temporary tables unless it contains only records copied from the real table.
    • Its quoting is flawed (as of NAV 2013 R2; I never inspected a later version of this codeunit). I once tried to use a better quoting mechanism by using a sequence of SETRANGE ... GETFILTER, only to discover that GETFILTER is not able to quote it's values correctly either. So SETFILTER(GETFLTER) might fail.

    I consider the fact, that it only works for tables with a single primary key field, a limitation, not a flaw, but still, you should be aware of this.

    Thank you for your answer :)
    In this case, how can I get a correct filter?
  • Options
    vaprogvaprog Member Posts: 1,125
    What about the filter you get is incorrect?
    vaprog wrote: »
    When you apply the returned filter string to the record immediately, do you get a different set of records as those you called GetSelectionFilterForXXX with?
Sign In or Register to comment.