Dynamics 365 Business Central: How to quickly check whether the user has read permission for the table in AL

Dynamics 365 Business Central

Hi, Readers.
Today I would like to share another mini tip about Business Central, how to quickly check whether the user has read permission for the table in AL.

We briefly discussed How to quickly check if the user has the SUPER permissions set via AL (Best practice) and Check whether a user has a specific permission set assigned before. This time we will discuss the permissions to read tables in depth again.
As you might know, when a user runs some functions but does not have permission, an error similar to the one below will be prompted.

Sorry, the current permissions prevented the action. (TableData 23 Vendor Read: Base Application)

Of course, there is nothing wrong with letting the system throw this error directly, but is it possible to automatically perform other operations when the user does not have read permission? Let me think of a simple example. When the user has read permission for TableData 23 Vendor, the Vendor List is opened. If not, the Contact List is opened. Yes, it can be done, we can use Record.ReadPermission() Method.

Record.ReadPermission() Method: Determines whether a user is granted read permission to the table that contains a record. This method can test for both full read permission and partial read permission that has been granted with a security filter.

Here is a simple example from the standard code.
codeunit 356 DateComprMgt:

Then the above example can be simply done:

Test video:

Give it a try!!!😁

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL