Checking for user-assigned roles
The NAV system checks permissions every time you look at data or run an object, but what if you need to check permissions manually? This recipe will show you how to examine a user ID to check for a specific role.
How to do it...
Create a new codeunit from Object Designer.
Add a global function called
VerifySecurity
that returns a Boolean value namedHasPermission
.This function should take in three parameters:
Name
Type
Length
RoleID
Code
20
CompanyRequired
Boolean
SuperAllowed
Boolean
Add the following code to the function:
HasPermission := CheckUserId(RoleID, CompanyRequired, SuperAllowed);
Add a global function called
CheckUserID
that returns a Boolean value.This function should take in the same three parameters as the
VerifySecurity
function.Add the following local variable to the function:
Name
Type
Subtype
Session
Record
Session
Add the following code to the function:
Session.SETRANGE("My Session", TRUE); IF NOT Session.FINDFIRST THEN EXIT...