Creating and Extending Permission Sets

Earn 25 points (50 with Pro) in two steps

  1. ① Read through the lesson — each section gets a ✓ as you scroll through it.
  2. ② When every section has a ✓, tap Complete lesson.

0 of 12 read · keep scrolling

✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro

Lesson: Creating and Extending Permission Sets in AL

Introduction: The Architecture of Security in Business Central

In the ecosystem of Microsoft Dynamics 365 Business Central, security is not an afterthought; it is a fundamental architectural component. When you develop custom solutions using the AL (Application Language) environment, you are essentially extending the capabilities of a complex enterprise resource planning system. If your custom application introduces new tables, pages, or codeunits, you are responsible for defining who can access these objects and what they can do with them. This is where Permission Sets come into play.

Permission Sets are the primary mechanism for controlling user access to data and system functionality. Without proper permission sets, your users will encounter "Permission Denied" errors, or worse, they might have access to sensitive business data they shouldn't see. Understanding how to create, extend, and manage these sets is a core competency for any AL developer. This lesson will guide you through the technical implementation of permission sets, from basic definitions to advanced extension patterns, ensuring your applications are both functional and secure.


Not read yet

Understanding the Permission Set Model

Before diving into the code, it is important to understand the two primary ways to define permissions in Business Central: the "classic" Permission Set object and the modern Permission Set Extension. In the past, permissions were managed largely through the user interface. Today, we define them directly in our AL projects, which allows us to treat security as code, version-control our access rules, and deploy them alongside our application features.

A Permission Set is effectively a collection of access rights. These rights are assigned to specific objects (tables, pages, reports, etc.) and define whether a user can Read, Insert, Modify, or Delete data, or whether they can Execute specific codeunits or report objects.

Callout: The Principle of Least Privilege The most critical rule in security engineering is the Principle of Least Privilege. This means every user or process should operate using only the minimum set of permissions necessary to complete their task. When designing your permission sets, avoid "blanket" permissions like TableData * = RIMD. Instead, be granular. If a user only needs to view a custom report, grant them 'Read' access to the underlying table, not full 'Delete' or 'Modify' rights.


Not read yet

Creating a New Permission Set Object

When you introduce new tables or functionality into Business Central, you should always accompany them with a new Permission Set object. This ensures that when your extension is installed, the necessary security groundwork is already laid.

The Syntax of a Permission Set Object

To create a new permission set, you define it using the permissionset keyword. You must provide a unique ID and a unique Name. The structure of the object includes the Assignable property, which determines if the set can be assigned to users through the user interface, and the Permissions block where the actual rules are defined.

permissionset 50100 "MyFeature Permission Set"
{
    Assignable = true;
    Caption = 'My Feature Access';
    
    Permissions = 
        tabledata "My Custom Table" = RIMD,
        tabledata "My Setup Table" = R,
        page "My Custom Page" = X,
        report "My Custom Report" = X;
}

Breakdown of Permission Types

The Permissions block uses specific syntax to grant rights. The letters RIMD stand for:

  • R: Read. Allows the user to view data in the table.
  • I: Insert. Allows the user to create new records in the table.
  • M: Modify. Allows the user to change existing records.
  • D: Delete. Allows the user to remove records.
  • X: Execute. Used for objects like Pages, Reports, and Codeunits to indicate the user can open or run them.

Note: When you grant RIMD on a table, you are granting full control over that data. Always consider whether 'Delete' or 'Modify' is truly necessary for the business process at hand.


Not read yet

Extending Permission Sets

Sometimes, you don't need to create an entirely new set of permissions. Instead, you might want to add specific permissions to an existing standard set provided by Microsoft or another ISV (Independent Software Vendor). This is where the permissionsetextension object becomes invaluable.

Why Extend Instead of Create?

Extending a permission set is superior to creating a new one when you want to augment existing roles. For example, if you have a custom table that needs to be accessed by the standard "Sales Order Processor" role, you don't want to create a new role and ask the administrator to assign two roles to every user. Instead, you extend the existing "Sales Order Processor" role to include access to your new table.

Implementation Example

The following code snippet demonstrates how to extend an existing permission set to include access to a custom table:

permissionsetextension 50101 "Extend Sales Processor" extends "Sales Order Processor"
{
    Permissions = 
        tabledata "My Custom Table" = RIMD;
}

This approach creates a clean, additive security model. When your extension is uninstalled, the modifications to the "Sales Order Processor" role are automatically removed, keeping the system configuration tidy and predictable.


Not read yet

Best Practices for Permission Set Management

Developing security is as much about process as it is about syntax. Follow these industry standards to ensure your application remains maintainable and secure.

1. Granular Permission Definitions

Avoid grouping all your permissions into a single, massive permission set. Instead, create logical groupings based on roles or functional areas. For example, create a "Setup" permission set for administrative tasks and a "User" permission set for daily operations.

2. Use Permission Set Groups

In Business Central, you can group multiple permission sets into a single logical unit known as a "Permission Set Group." This is a UI-based configuration, but you should design your AL objects with the intent that they will be part of these groups.

3. Testing Permissions

Never assume your permissions work as intended. As a developer, you should always test your code using a user account that has the minimum permissions required. If you test as a "Super" user, you will never discover the missing permissions that will inevitably cause your end-users to crash.

Warning: The 'Super' User Trap A common mistake is testing features while logged in as a 'Super' user. 'Super' users bypass all permission checks. When you deploy your app, users will immediately encounter errors because you failed to define the necessary permissions for the 'Standard' user profile. Always test in a non-admin environment.

4. Naming Conventions

Use descriptive names for your permission sets. Instead of MyPermSet1, use Sales-Custom-Read or Inventory-Admin-Full. This helps administrators identify exactly what the permission set does without needing to inspect the code.


Not read yet

Advanced Scenarios: Security Filtering

Sometimes, granting access to a table isn't enough. You may want to grant access to a table, but restrict the records that the user can see based on a filter. This is known as Security Filtering.

For example, you might want a "Salesperson" to only see records in the "Customer" table where the "Salesperson Code" matches their own ID.

Implementing Security Filters in AL

You can define security filters directly within your Permission Set object. This restricts the data scope at the database level.

permissionset 50102 "Limited Sales Access"
{
    Assignable = true;
    Permissions = 
        tabledata Customer = R,
        tabledata Customer where("Salesperson Code" = field("Salesperson Code")) = RIMD;
}

This is an incredibly powerful feature. By defining these filters in the permission set, you ensure that the security policy is enforced regardless of how the user accesses the data (e.g., via a list page, a report, or an API).


Not read yet

Comparison of Permission Approaches

Feature New Permission Set Permission Set Extension
Purpose Create new, distinct roles Augment existing roles
Maintenance Independent of other roles Dependent on the base role
Best Use Case Unique functional areas Adding custom tables to standard roles
Cleanup Removes only the set Removes only the added permissions

Common Pitfalls and Troubleshooting

Even experienced developers encounter issues with permissions. Here are the most frequent challenges and how to resolve them.

Missing 'Execute' Permissions

A very common error is granting RIMD on a table but forgetting to grant X (Execute) on the Page or Report that displays that table. Users will see the data in a lookup, but they will be unable to open the page to view the details. Always pair table permissions with the corresponding page execution permissions.

Dependency Issues

If your permission set refers to an object in another extension, ensure that your app.json file has the correct dependency defined. If the dependency is missing, the compiler will throw an error, but if the dependency is present but the object is renamed or deleted, your permission set will fail at runtime.

The "TableData" vs "Table" Distinction

In AL, you grant permissions to tabledata. You do not grant permissions to table objects. If you see an error mentioning table permissions, check your syntax. You are always controlling access to the data within the table, not the table object definition itself.

Troubleshooting Steps

If a user reports a permission error:

  1. Identify the Object: Use the "Help" or "About" feature in Business Central to identify the exact object ID causing the error.
  2. Check the Permission Set: Verify if the user is assigned a permission set that includes that object.
  3. Review the Scope: Check if a security filter is being applied that is accidentally excluding the records the user needs to see.
  4. Check for Conflict: Ensure no other permission set is explicitly denying access (though in Business Central, permissions are additive, so explicit denies are rare).

Not read yet

Step-by-Step: Creating a Secure Workflow

To solidify your understanding, let's walk through the creation of a secure feature.

Scenario: You are building a "Project Tracking" app. You have a table called "Project Header" and a page called "Project Card."

  1. Define the Table: Create your table object.
  2. Define the Page: Create your page object.
  3. Create the Permission Set:
    • Create a new file ProjectPermissions.permissionset.al.
    • Define the object with Assignable = true.
    • Grant RIMD to tabledata "Project Header".
    • Grant X to page "Project Card".
  4. Assign the Set: In the Business Central client, navigate to "Permission Sets," find your new set, and assign it to a test user.
  5. Verify: Log in as the test user and ensure you can open the project card and create new projects.
  6. Refine: If you realize users should not be able to delete projects, change the RIMD to RIM in your permission set file and re-publish.

Not read yet

Deep Dive: The Role of System Permissions

Beyond your own custom objects, your application might need to interact with standard Business Central tables. For instance, your project tracking app might need to read the Customer table to link a project to a client.

In this case, you should not add tabledata Customer = R to your own permission set if it isn't strictly necessary. Instead, rely on the user having the standard "Customer" permission set already. However, if your code requires the user to perform an action on the Customer table that a standard user wouldn't normally do, you should use the Permissions property on the specific codeunit or table that executes that logic.

Using the Permissions Property on Objects

Sometimes, you want a specific piece of code to run with elevated permissions, regardless of the user's assigned permission sets. You can use the Permissions property on a Codeunit or Table object to accomplish this.

codeunit 50105 "Project Management Logic"
{
    Permissions = tabledata "Customer" = r;

    procedure GetCustomerName(CustNo: Code[20]): Text
    var
        Cust: Record Customer;
    begin
        if Cust.Get(CustNo) then
            exit(Cust.Name);
    end;
}

This is known as "Elevated Permissions" or "Permission Wrapping." Use this sparingly. It is a powerful tool to ensure your code works even if the user lacks broad access to the underlying tables, but it can create security loopholes if used carelessly.


Not read yet

Managing Permissions in Multi-Tenant Environments

When developing for multi-tenant environments or SaaS (Software as a Service), permission management becomes even more critical. You cannot rely on manual, one-off configurations. Everything must be defined in your AL code.

The Role of Extensions

When you publish an extension, the permission sets defined within it are automatically registered in the system. This means your security model is deployed alongside your application. This is a massive advantage over legacy systems where security often had to be configured manually in every single client environment.

Best Practices for SaaS

  • Version Control: Keep your permission set definitions in Git. If you change a permission, the audit trail should show who changed it and why.
  • Automated Testing: Include tests that verify the presence of permission sets and their content.
  • Documentation: Even though the code is self-documenting, maintain a simple document that explains the functional roles your permission sets support.

Not read yet

Common Questions and FAQs

Q: Can I use wildcards in permissions?

A: Yes, you can use * for objects, but be extremely careful. tabledata * = R would grant read access to every table in the system. This is a significant security risk and should almost never be used in a production environment.

Q: What happens if I rename a table?

A: If you rename a table in your code, you must update your permission set references. If you don't, the compiler will throw an error, preventing you from publishing your app. This is a good safety feature.

Q: How do I handle permissions for API pages?

A: API pages follow the same security rules as standard pages. If your API is intended for an external service to read data, ensure the service account has a permission set assigned that grants 'Read' access to the relevant tables and 'Execute' access to the API page.

Q: Are permission sets additive?

A: Yes. If a user has "Permission Set A" (Read access) and "Permission Set B" (Modify access), they will have Read and Modify access. There is no way to "subtract" permissions using a different set.


Not read yet

Key Takeaways

  1. Security as Code: Always define your permission sets in AL code. This makes your security model version-controlled, repeatable, and easy to deploy.
  2. Principle of Least Privilege: Grant the absolute minimum access required. Start with no access and add only what is necessary for the business task.
  3. Granularity Matters: Prefer multiple small, functional permission sets over one large, monolithic set. This makes management easier as your application grows.
  4. Pair Tables with Pages: Always remember that access to data (TableData) must be accompanied by access to the UI (Page) to allow users to interact with that data effectively.
  5. Test Without 'Super': Always test your application using a user account with limited permissions. This is the only way to ensure your permission sets are actually functional.
  6. Use Extensions for Augmentation: When you need to add your custom objects to standard roles, use permissionsetextension rather than creating entirely new roles.
  7. Security Filters: Leverage security filters within your permission sets to enforce row-level security, ensuring users only see the data relevant to their specific role or department.

By mastering these concepts, you transition from being a developer who "writes code" to a developer who "builds secure solutions." Security is the foundation upon which trust in your software is built; treat your permission sets with the same rigor as your business logic.

As you continue your journey in AL development, keep these practices at the forefront of your mind. Every time you create a new table, ask yourself immediately: "Who needs to see this, and what are they allowed to do with it?" Answering that question in your AL code is the hallmark of a professional Business Central developer.

Not read yet

Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.