Recently I saw an interesting question on the Microsoft Dynamics NAV Forum.
Dear All,(+) How to disable filters by cal. – Microsoft Dynamics NAV Forum Community Forum
Suppose we apply two filters
How to disable filter for line 2 by C/AL.
This is actually very simple, but some developers may not have noticed, so in this post, I would like to briefly talk about how to remove or cancel one filter in AL.
PS: The SetRange method provides a quick way to set a simple filter on a field.
Record.SetRange(Any [, Any] [, Any]) Method:
First, you can of course use Record.Reset() Method and then set the filter conditions from the beginning.
Record.Reset() Method: Removes all filters, including any special filters set by MarkedOnly, changes fields select for loading back to all, and changes the current key to the primary key. Also removes any marks on the record and clears any AL variables defined on its table definition.
Take the above problem as an example, three filters are set and only the third one needs to be canceled, but if you use Reset, you need to set the filter1 and filter2 again.
rec.setrange(field1, fieldref); rec.setrange(field2, fieldref); rec.setrange(field3, fieldref); rec.Reset(); rec.setrange(field1, fieldref); rec.setrange(field2, fieldref);
So, what is the best way? You just omit the FromValue and ToValue parameters in Setrange, all filters set for that field are removed.
rec.setrange(field1, fieldref); rec.setrange(field2, fieldref); rec.setrange(field3, fieldref); rec.setrange(field3);
Let’s see more details.
The conclusion is very simple:
Set filter: Setrange(Field,From,To)
Remove filter: Setrange(Field)
Hope this will help.
Thanks for reading.