top of page
Daniel Gorski

🚀 Filter Token Master đŸ•”ïžâ€â™‚ïž | Simplifying Data Filtering with 😎 Custom Tokens! 💡

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 the demo:



115 Ansichten0 Kommentare

Aktuelle BeitrÀge

Alle ansehen

Comments


bottom of page