I have added code to restrict users from viewing/accessing Sales Orders in the Page 9305-Sales Order List based on the Salesperson/Purchaser code in the Sales Order. Each user is assigned a Salesperson in the User setup page. All is fine and the Sales Order List display only the expected sales orders.
But the user can now clear the page filter and see all the sales orders irrespective of the coded filter. I would like to know how can I restrict users with certain rights from clearing the filter.
Take a look at the documentation on FILTERGROUP. If you set to something above 6 (I personally use above 10, just to stay out of the way), set the record filter, then set filtergroup back to its original value, you users won’t be able to clear the filters you’ve set in the custom filtergroup.
Yes, it’s not only OK to do that, but it actually won’t work if you don’t. If you leave the setting on Filtergroup(10), and users are working in that filtergroup, then they can clear it. That’s the whole point of changing back.
Now, if you really want to be slick about this, first assign the value of the current filtergroup to a variable, then use that variable to return to the initial state.
So, you would then see something like:
MyIntVar := filtergroup;
filgergroup(10);
setrange…
filtergroup(MyIntVar);
Doing it this way, you don’t inadvertently leave the filtergroup in a different condition than you found it in.
So, just posting a quick follow-up after reading again your last question.
Think of filtergroups as completely independent filter sets, in terms of setting the values. In terms of how they work, they are all applied to the record at once. So, if I set a filter on the Salesperson Code in filtergroup(2) so that the value must begin with ‘A*’, then go into filtergroup(10) and set another filter on Salesperson Code so that the value must begin with “B*”, when I’m finished, I’ll have an empty set, because no Salesperson Code can begin with both A and B. NAV applies both filters equally. Now, that doesn’t mean that you can’t switch back and forth among the groups to set different filters. It only means that you need to keep track of what you’re doing. For example, if in your custom code you had set a filter on Responsibility Center in filtergroup(10), you may run into the same issue because of the filter set in the code just above in filtergroup(2).
So, short answer is yes, you can have multiple calls to filtergroup in the same trigger. You just need to ensure that you get the end result that you’re expecting by making sure that you’re not creating conflicting filter expressions like the ones I described.