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:
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
Comments
2) All functions like COPYFILTERS or GETVIEW are working only with active FILTERGROUP, you can use that...
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
I am using Navision v4.0 (4.0 SP2)
Using COPYFILTERS does not seem to work. I added this code to OnOpenForm()
Unfortunately, when user clicks "Show All", the filters are cleared. I then tried
"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:
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,
Bill
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
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 code
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,
Bill
Why did you use the filtergroup(200) instead of filtergroup(2)?
Only filtergroup(2) cannot be removed by user.
Matteo
As I wrote earlier, the following code works fine:
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 tried
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,
Bill
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,
Bill
Rereading the thread, I tried Kamil's suggestion above.
With the above code, the first CONFIRM dialog showed no filters set, and the second did show filters set. This does not look promising.
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,
Bill
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,
Bill
and the users are not able to remove filters.