D365 Business Central Filter Tokens - Locus IT Services

D365 Business Central Filter Tokens

Locus IT ServicesNewsD365 Business Central Filter Tokens

D365 Business Central Filter Tokens

In the client, when filtering lists utilizing the filter pane, users can enter the D365 Business Central Filter Tokens, which are special words that resolve to one or more values. This powerful feature makes filtering simple by reducing the need to navigate to other pages to look up values to enter as filter criteria.

There are several useful filter tokens available in Business Central. For example, entering %mycustomers in a Customer No. field will rectify to the set of customers in the users My Customers list such as 1001|1002, making it easy to find relevant sales orders for customers 1001 and 1002.

You can insert custom filter tokens and make these accessible in any language and across the application. To insert your custom filter token, you need to describe the token word that users will enter as filter criteria and define a handler that resolves the token to a concrete value at run time.

D365 Business Central Filter Tokens Overview

Defining the Token Word and the Handler

To create the desired token word, start by defining a multi-language text string for your word. Subscribe to the OnBeforeMakeTextFilter or OnAfterMakeTextFilter events associated with the MakeTextFiltermethod from the TextManagement codeunit.

In the event subscriber, if the value of the TextFilterText parameter consists of the Microsoft Dynamics Business Central token string advance to process its value and construct the final filter string. If the filter string must consist of multiple values, you must handle the operators that joins them together, by inserting the | filter symbol (OR operation).

Complete the operation by setting the value of the TextFilterText parameter to the value of the final filter string. Filter criteria will often consist of symbols along with filter tokens. It is recommended that you only modify the filter token you have introduced and preserve the rest of the filter string.

Example

This example shows how you can use the guidelines above to create the %MYTOKEN filter token. This will return a filter with the accounts marked as favorite by the user.

codeunit 50101 MyAccountFilterTokenSimple
{
[EventSubscriber(ObjectType::Codeunit, Codeunit::TextManagement, ‘OnAfterMakeTextFilter’, ”, true, true)]
local procedure FilterMyAccountsOnAfterMakeTextFilter(var Position: Integer; var TextFilterText: Text)
var
MyAccountTxt: Label ‘MYTOKEN’;
MyAccount: Record “My Account”;
MaxCount: Integer;
begin
if StrLen(TextFilterText) < 3 then
exit;
if StrPos(UpperCase(MyAccountTxt), UpperCase(TextFilterText)) = 0 then
exit;

MaxCount := 2000;
MyAccount.SetRange(“User ID”, UserId);
if MyAccount.FindSet() then begin
MaxCount -= 1;
TextFilterText := MyAccount.”Account No.”;
if MyAccount.next <> 0 then
repeat
MaxCount -= 1;
TextFilterText += ‘|’ + MyAccount.”Account No.”
until (MyAccount.Next = 0) or (MaxCount <= 0);
end;
end;
}

To try it out in the client, open the Charts of Accounts page, filter on No. field, and type in a sub string that starts the same way with the chosen token word, like %MYTO. For more information on Microsoft D365 Business Central Filter Tokens, please contact us.

Locus IT Project Management Office
What’s it?