What Every BC Developer Should Know About SecurityFiltering in AL

TURKI HelaTURKI Hela
2 min read

If I were a Business Central developer just starting with AL, I'd want to quickly learn how security filters work in code and how to manage them.

In Business Central, permission sets and security filters determine what users can see. When writing AL code, we can override, enforce, or validate these filters according to our needs. This is where the SecurityFiltering property becomes very useful.

How to Add a Security Filter in Business Central

  • Step 1: Go to "Permission Sets"

  • Step 2: Select or create a Permission Set

  • Step 3: Add Table Permissions

  • Step 4: Add a Security Filter

    Let’s Learn How to Use SecurityFiltering in AL

    When building extensions in Business Central, it's important to control what data users can access, not only in the UI but also in the code.

    🎯 Syntax

    [SecurityFiltering(SecurityFilter)]

    var CustomerRec: Record Customer;

    The available values for SecurityFiltering are:

    • SecurityFilter: Enforces the user’s security filters (default behavior).

    • Filtered: Enforces filtering based on the user’s security setup.

    • Ignored: Bypasses all security filters on the record.

    • Validated: Enforces the security filters and throws an error if filters are violated.

When to Use It

  • Use SecurityFiltering(SecurityFilter) or Filtered when you want to respect the user's data access.

  • Use Ignored only when it's necessary for system-level tasks and you’re sure you need full access to the data.

  • Use Validated when you want to explicitly ensure the code errors out if the current user shouldn't access that data.

Example

You want to calculate total inventory across all locations, even if the user has a security filter on Location filter

    procedure GetTotalInventory(ItemNo: Code[20])
        var
            Item: Record "Item";
            TotalQty: Decimal;
        begin
            Item.SecurityFiltering := SecurityFilter::Ignored;
            Item.get(ItemNo);
            Item.calcfields("Inventory");
            TotalQty := Item.Inventory;
            Message('Total Quantity for item %1 = %2', ItemNo, TotalQty);
        end;
0
Subscribe to my newsletter

Read articles from TURKI Hela directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

TURKI Hela
TURKI Hela