moving filters from one FILTERGROUP to another

billstoll
Member Posts: 8
A form is called with some filters in FILTERGROUP(0). I don't know which fields have filters. In OnOpenForm(), I would like to move all filters to FILTERGROUP(200), as I do not want users navigating to this form to be able to change the filters that were passed in.
First thing I tried was:
but unfortunately this does not affect FILTERGROUP(200) in Rec. If I could translate a fieldref back to a regular field, I could do the SETFILTER calls in Rec instead of myfieldref, but I can't figure out how to do that.
Hoping I don't have to go to all the places that call this form and set up FILTERGROUPs in them.
Thanks for any help,
Bill
First thing I tried was:
myrecordref.GETTABLE(Rec); FOR i := 1 TO myrecordref.FIELDCOUNT DO BEGIN myfieldref := myrecordref.FIELDINDEX(i); oldfilter := myfieldref.GETFILTER; IF myfieldref.ACTIVE AND (oldfilter <> '') THEN BEGIN myrecordref.FILTERGROUP(200); myfieldref.SETFILTER(oldfilter); myfieldref.FILTERGROUP(0); END; END;
but unfortunately this does not affect FILTERGROUP(200) in Rec. If I could translate a fieldref back to a regular field, I could do the SETFILTER calls in Rec instead of myfieldref, but I can't figure out how to do that.
Hoping I don't have to go to all the places that call this form and set up FILTERGROUPs in them.
Thanks for any help,
Bill
0
Comments
-
1) You do not need to use RecordRef for that. Use just the Rec and you are done.
2) All functions like COPYFILTERS or GETVIEW are working only with active FILTERGROUP, you can use that...0 -
Thanks for replying, Kamil.
I am using Navision v4.0 (4.0 SP2)
Using COPYFILTERS does not seem to work. I added this code to OnOpenForm()FILTERGROUP(200); COPYFILTERS(Rec); FILTERGROUP(0);
Unfortunately, when user clicks "Show All", the filters are cleared. I then triedmyrec.FILTERGROUP(200); myrec.COPYFILTERS(Rec); FILTERGROUP(200); COPYFILTERS(myrec); FILTERGROUP(0);
"Show All" still clears the filters. Perhaps I am doing it wrong?
If I know which fields have filters, I am all set. Suppose "Group No." has the only filter. Then I can do this:myfilter := GETFILTER("Group No."); FILTERGROUP(200); SETFILTER("Group No.", myfilter); FILTERGROUP(0);
Now "Show All" does NOT clear the filter. However, to do it this way in the general case, I would have to hard code a GETFILTER call for every field in the table to check for existence of a filter and then assign it to filtergroup 200. That is what I am trying to avoid.
Thanks,
Bill0 -
Check that GETFILTERS will return some filters before you switch the filtergroup back to 0 on the rec (e.g. by using MESSAGE). Just for check...0
-
In OnOpenForm() I added the line
MESSAGE(GETFILTERS);
at the top, and it did indeed show that two filters were set. There is no other code in OnOpenForm.
I knew there were filters being set anyway, since when I run the form I only see one line of output. Clicking "Show All" to clear the filters results in many lines being shown. This is what I am trying to avoid by creating the filtergroup.
So, at this point, I am still stuck with no way to copy filters to a different filtergroup except to write this block of codemyfilter := GETFILTER(myfirstfield); IF myfilter <> '' THEN BEGIN FILTERGROUP(200); SETFILTER(myfirstfield, myfilter); FILTERGROUP(0); END;
and repeat it for every field in the table (ugh).
I could also parse the text output of GETFILTERS, but I don't know of a way to map a text field name to the real field in the table, so would need a giant CASE statement to do it (ugh again).
Still seems there should be a better way.
Thanks,
Bill0 -
billstoll wrote:Thanks for replying, Kamil.
I am using Navision v4.0 (4.0 SP2)
Using COPYFILTERS does not seem to work. I added this code to OnOpenForm()FILTERGROUP(200); COPYFILTERS(Rec); FILTERGROUP(0);
Unfortunately, when user clicks "Show All", the filters are cleared.
Why did you use the filtergroup(200) instead of filtergroup(2)?
Only filtergroup(2) cannot be removed by user.
MatteoReno Sistemi Navision Developer0 -
Hi Matteo,Why did you use the filtergroup(200) instead of filtergroup(2)?
Only filtergroup(2) cannot be removed by user.
As I wrote earlier, the following code works fine:myfilter := GETFILTER("Group No."); FILTERGROUP(200); SETFILTER("Group No.", myfilter); FILTERGROUP(0);
The user cannot clear the filter using the "Show All" button at the top of the form, despite the fact that I am using filtergroup(200) and not filtergroup(2). However, I would have to repeat that code for every field in the table.
After getting your note, I triedFILTERGROUP(2); COPYFILTERS(Rec); FILTERGROUP(0);
But this did not work - I was able to click "Show All" and the filters were cleared just as before. I suspect that the problem is that the above code does not actually create filters in filtergroup(2) - it does something else, not sure what.
My bottom line question is: how to keep the user from clearing the filters in place when the form is invoked? Assuming filtergroups are the correct path, how do I use filtergroups in THIS form (e.g., how do I move filters from one filtergroup to another?) efficiently. I have ugly workarounds already (set the filtergroups in all the calling forms, change this form to make hard coded calls to SETFILTER for every field in the table that has a filter). Perhaps I must do one of those?
Thanks,
Bill0 -
This is what I did
where Filters is a text variable
Filters := GETVIEW;
FILTERGROUP(24);
SETVIEW(Filters);
FILTERGROUP(0);0 -
This is what I did
where Filters is a text variable
Filters := GETVIEW;
FILTERGROUP(24);
SETVIEW(Filters);
FILTERGROUP(0);
I just tried the above, but clicking "Show All" still clears the filters. Are you running a later version of Navision? We are running version 4 (4.0 SP2)
Thanks,
Bill0 -
Check that GETFILTERS will return some filters before you switch the filtergroup back to 0 on the rec (e.g. by using MESSAGE). Just for check...
Rereading the thread, I tried Kamil's suggestion above.FILTERGROUP(200); COPYFILTERS(Rec); IF CONFIRM('filtergroup 200: %1', TRUE, GETFILTERS) THEN ; FILTERGROUP(0); IF CONFIRM('filtergroup 0: %1', TRUE, GETFILTERS) THEN ;
With the above code, the first CONFIRM dialog showed no filters set, and the second did show filters set. This does not look promising.myrec.COPYFILTERS(Rec); FILTERGROUP(200); COPYFILTERS(myrec); IF CONFIRM('filtergroup 200: %1', TRUE, GETFILTERS) THEN ; FILTERGROUP(0); IF CONFIRM('filtergroup 0: %1', TRUE, GETFILTERS) THEN ;
With the above code, both CONFIRM dialogs showed filters set.
Unfortunately, neither prevented "Show All" from clearing all filters. Grasping at straws, I tried inserting a RESET between the first and second lines above, but it did not change anything. Both CONFIRM dialogs still showed filters set. Surprised me a little, since the RESET should have cleared the filters in filtergroup(0). This convinces me that COPYFILTERS is not paying attention to the assigned FILTERGROUP - perhaps it assigns the filters to all groups (??), or more likely some system group that always shows up on GETFILTERS.
Thanks,
Bill0 -
It looks like there is no solution to this problem.
In case anyone is still following this thread, I decided to create FILTERGROUPs in the calling forms.
I would still love to know if there is a real solution (how to copy filters in a form's record from one FILTERGROUP to another).
Thanks,
Bill0 -
hi i used this code:
if HASFILTER then begin ltxtfilters := GETVIEW; filtergroup(10); SETVIEW(ltxtfilters); filtergroup(0); end;
and the users are not able to remove filters.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