Wrong filter from codeunit 46 - GetSelectionFilter

poppins
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
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

0
Answers
-
Hi,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.0 -
Hi,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?0
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