Dynamics NAV 4.0 SP 2

You can test this in Sales Order form.

Here is the normal usage of filter groups using SETFILTER in case you’d like to make unremovable filters:
SETFILTER(“Location Code”,‘MyLocation’);

However the working equivalent of this using SETVIEW is:
SETVIEW(‘where(Location Code=FILTER(MyLocation))’);

I’m fine with the SETVIEW syntax, but I can’t understand why filtergroups are used differently in both cases.

Could you give me some reasonable explanation?

Btw I’m posting regularly my thoughts about Dynamics NAV here:

88 views and still no answer.

Does anybody knows something about the above?

Well i was one of those viewers and not really sure what the question is? In the frst instance you change the filter group to 2 then set the filter, the set the filter group back to 0, this allows the user to set additional filters but not clear the original filter set in 2. In the second instance you set the view on the table then you set the filter group to 2, thus not allowing the user to add any additional filters.

Not really sure what the question is?

The second variant you are talking about is definitely NOT the same thing.

the equivalent for your SETFILTER would be :

SETVIEW(‘where(Location Code=FILTER(MyLocation))’);

There is basically no difference between teh SETVIEW and SETFILTER command except that the syntax is a little more complicate and you can set multiple filters AND a key as well as a sorting order (ascending or descending) at the same time.

The bigger issue in this case is the usage of FILTERGROUP.

Navision supports multiple filter levels whereby two of these are the most important for usage inside code:

FILTERGROUP(0): Filtergroup zero is the level of filters the user normally has access to.
FILTERGROUP(2): Filtergroup two is the level of filters Navision uses i.e. for mainform/subform relationship. Example: in the sales order form it makes sense to link the lines to the header displayed and not let the user remove the filter for the primary key fields of the header.

Actually Navision allows the user access to the filters within the currently selected filtergroup. This means - based on your example - you are setting your location filter within filtergroup zero and then switch over to filtergroup two. So the user does not have access to the filters set in filtergroup zero anymore (as it is not the “active” filtergroup) but therefor has access to the filters set in filtergroup two.


Here are some details, that actually exist in my previous post.

I want to make unremovable filter. For this reason I use FILTERGROUP(2). However, I can not use SETFILTER and I must use SETVIEW. The normal usage of FILTERGROUP(2) and SETFILTER, when you want to make unremovable filters, is the first piece of code. I tried to change the SETFILTER line with SETVIEW line, but it didn’t work. Then I found that it works when it is written like the second piece of code. My only problem now is that both pieces of code do not look consistent and I’m asking why.


Theoretically the system should work as you explain in your last paragraph, but it is not. You can try these pieces of code.

I’m using these things for quite some time and had never any problems, can you exactly explain where in the form to place your code ?

And what exactly means “didn’t work” ?

Do you mean the filter was not set ?

Or do you mean the filter was visible ?

Or do you mean SETFILTER popped up with an error ?

Try it in the Sales Order form in the OnOpen trigger, no matter in the beginning or in the end of the trigger. First piece of code is fine. If I change the SETFILTER line with the SETVIEW line so that the code become:




This is expected to have the same behaviour as the first piece of code, but it is not. The filter is set, but it is visible and removable.

If I use the second piece of code, it seems to be OK, but still I’m worried, because theoretically it should do something else.

Withinthe description (C/SIDE Help) for the FILTERGROUP command, only SETRANGE and SETFILTER are referenced.

This seems to mean that SETVIEW command always uses FILTERGROUP(0).
That could be the reason that you still see the filter.

The real question is why the SETFILTER command is not doing what you expect.

Did you try to use SETRANGE(“Location Code”,‘MyLocation’) or SETFILTER(“Location Code”,’%1’,‘MyLocation’) instead ?