Adding roles through the User Setup table
A common way to give permissions to users is by adding a field to the User Setup table. Although not the best practice, this recipe will show you how this common type of permission works.
How to do it...
Design the User Setup table (91) from Object Designer.
Add a Boolean field named Sample Permission with ID as 50000.
Save and close the table.
Design the User Setup form (119).
Use the Field Menu to add a column for the Sample Permission field.
Save and close the form.
Create a new codeunit from Object Designer.
Add the following global variable:
Name
Type
Subtype
UserSetup
Record
User Setup
Add the following code to the
OnRun
trigger:IF NOT UserSetup.GET(USERID) THEN ERROR('You do not have permission to perform this action.'); IF UserSetup."Sample Permission" THEN MESSAGE('Permission granted.') ELSE ERROR('You do not have permission to perform this action.');
Save and close the codeunit.
How it works...
We start by adding a field that will give or deny...