# What Every BC Developer Should Know About SecurityFiltering in AL

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
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748269004855/6f5ec7b5-2552-4e68-80df-2fe5c4d6795a.png align="center")
    
* Step 4: Add a Security Filter
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748269075586/a83bc50c-cf96-4952-88a5-6f84fbbb2402.png align="center")
    
    ## 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`
    
    ```basic
    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;
    ```
