SETPERMISSIONFILTER(Record)

headley27headley27 Member Posts: 188
I have a question as a matter of interest only.

I was completely perplexed why a simple SETFILTER, FIND('-') routine was giving me a Read Error.

I had set a Security Filter on the a field in the Sales Header.

Although the user could access all the documents that would have been returned by the filter directly (via the Sales Quote Form, Sales Order Form, etc.), the user would receive a Read Error when performing a lookup.

I came across SETPERMISSIONFILTER and it solved my problem.
SalesHeader.SETPERMISSIONFILTER;
IF SalesHeader.FIND('-) THEN ........
Can someone tell me why Navision wouldn't do this by default?
The whole reason for entering a Security Filter is to filter records.

What could be gained by not including SETPERMISSIONFILTER?
All I received was an Error Message (and a headache ](*,) ).

Thank you very much in advance.

Answers

  • dmccraedmccrae Member, Microsoft Employee Posts: 144
    The reason is that when running AL code, automatically applying an arbitrary (security) filter that the business logic does not itself control can easily cause data corruption, e.g. by copying records to a target table that has been limited to the security filter, such as a particular Location Code etc.

    In the UI there is no harm in automatically stripping out the records that the user may not see, and this is desired - but in running code it is left up to the developer to determine if applying the security filter is safe, by explicitly using SETPERMISSIONFILTER, since it very much depends on the security filter you're using.
    Dean McCrae - Senior Software Developer, NAV Server & Tools

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • headley27headley27 Member Posts: 188
    Great Answer!! =D>

    Thank you very much.
Sign In or Register to comment.