Simplifying Data Filtering

Filter Token Master šŸ•µļøā€ā™‚ļø | Simplifying Data Filtering with šŸ˜Ž Custom Tokens! šŸ’”

Daniel Gorski
Daniel Gorski 24. Juli 2023
2 Min. Lesezeit

In Business Central, there are several built-in filter tokens available, and users can also define custom filter tokens to suit their specific needs. Custom filter tokens can be defined in any language and are accessible across the application.

To add a custom filter token in Business Central, you need to do the following:

  1. Define the Token Word: Decide on the special word that users will enter as the filter token, such as "%mycustomers".
  2. Implement the Token Resolver: You need to define a handler that resolves the filter token to a concrete value at runtime. This handler will be responsible for providing the relevant values that match the token. For example, if the user enters "%mycustomers," the handler should resolve it to the list of customers from the "My Customers" list.
  3. Register the Custom Filter Token: Once you have defined the token word and implemented the token resolver, you need to register the custom filter token in Business Central so that it becomes available for users to use in the filter pane.

By leveraging filter tokens, users can perform complex filtering operations with ease, improving their productivity and the overall user experience within Business Central.

All you need to do is subscribing to the OnResolveTextFilterToken Event in Codeunit "Filter Tokens.

In my example I'am using my own Salespersoncode from User Setup.

codeunit 50008 "ABC Custom Filter Token"
{
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Filter Tokens", 'OnResolveTextFilterToken', '', true, true)]
    local procedure FilterMySalesperson(TextToken: Text; var TextFilter: Text; var Handled: Boolean)
    var
        UserSetup: Record "User Setup";
        SPNTok: Label 'SPN', Locked = true;
    begin
        if not UserSetup.Get(UserId()) then
            exit;

        if UserSetup."Salespers./Purch. Code" = '' then
            exit;

        if StrLen(TextToken) < 3 then
            exit;

        if StrPos(UpperCase(SPNTok), UpperCase(TextToken)) = 0 then
            exit;

        Handled := true;
        TextFilter := UserSetup."Salespers./Purch. Code";
    end;
}

šŸ” See it in Action!

Demo using custom token

beyondit
tech
Business Central
Filter Tokens
Customization
User Setup
Codeunit
E-Invoice Viewer for Business Central

New Open-Source E-Invoice Viewer for Business Central

View and convert German XRechnung XML files directly in Microsoft Dynamics 365 Business Central with the new open-source E-Invoice Viewer from BEYONDIT.

ā–¶ Read More
Read More
E-Invoice Viewer für Business Central

Neue Open-Source-App: E-Invoice Viewer für Business Central

Lesen und konvertieren Sie deutsche XRechnung-XML-Dateien direkt in Microsoft Dynamics 365 Business Central mit dem neuen Open-Source E-Invoice Viewer von BEYON

ā–¶ Read More
Read More