FieldRef.IsOptimizedForTextSearch() Method in Business Central 2025 Wave 1

With the release of Business Central 2025 Wave 1, Microsoft continues to empower developers with more control and insights into the performance and behavior of their extensions. Among the new additions is the method FieldRef.IsOptimizedForTextSearch(), designed to help developers make more performance-conscious decisions when implementing search functionalities.

💡 What is FieldRef.IsOptimizedForTextSearch()?

FieldRef.IsOptimizedForTextSearch() is a method that returns a Boolean value indicating whether a particular field in a table is optimized for text search.

It is a method on the FieldRef data type, which is used in AL code to dynamically refer to fields of records, especially in scenarios involving field iteration, metadata handling, or dynamic filters.

✅ Syntax:

Boolean := FieldRef.IsOptimizedForTextSearch();

⚙️ How to Optimize a Field for Text Search

While IsOptimizedForTextSearch() only checks if a field is optimized, setting it up is done via the table metadata or through the table schema in AL.

To mark a field for text search:

field(10; Description; Text[100])
{
Caption = 'Description';
DataClassification = ToBeClassified;
OptimizeForTextSearch = true;
}

Setting OptimizeForTextSearch = true; enables text search optimization (depending on SQL backend settings as well for on-premise).

Lets see how we can utlize above method to check optimize search

var
    MyRecordRef: RecordRef;
    MyFieldRef: FieldRef;
    IsOptimized: Boolean;
begin
    MyRecordRef.Open(Database::Customer);
    if MyRecordRef.FindSet() then begin
        MyFieldRef := MyRecordRef.Field(Name); // Let's check the "Name" field
        IsOptimized := MyFieldRef.IsOptimizedForTextSearch();

        if IsOptimized then
            Message('The "%1" field in the Customer table is optimized for text search.', MyFieldRef.Name())
        else
            Message('The "%1" field in the Customer table is NOT optimized for text search.', MyFieldRef.Name());
    end;
    MyRecordRef.Close();
end;

To be optimized for full-text search, a field typically needs:

  • A Text or Code data type.
  • An active index that supports full-text search (defined in the table metadata or via table extensions).
  • Proper settings in SQL Server or Azure SQL (if full-text search is enabled).

The FieldRef.IsOptimizedForTextSearch() method is a small but powerful tool in the AL developer’s toolkit. Whether you’re designing smarter search UIs or optimizing performance in large datasets, this method gives you the metadata visibility to make informed choices.

By leveraging this feature, you can:

  • Improve app performance
  • Avoid slow queries
  • Create better user experiences

Stay tuned for more..

How to export data using TextBuilder in Business central.

Today we will see how we can data from business central table using new data type Text Builder.

To check how this data type work build small program as below which pick up data from customer table and export the data in text file.

pageextension 50101 CustomerMasterExtension extends "Customer List"
{
    actions
    {
        addlast(General)
        {
            action(DataExport)
            {
                Caption='Data Export to Text';
                ApplicationArea=All;
                PromotedCategory=Process;
                Promoted=true;
                Image=ExportDatabase;
                trigger OnAction()
                var
                CustomerMaster :Record Customer;
                Tempblob:Codeunit "Temp Blob";
                TextFileBuilder :TextBuilder;
                FileName:Text;
                InStreamData:InStream;
                OutStreamData:OutStream;
                begin 
                    FileName:='CustomerData.Txt';
                    TextFileBuilder.AppendLine('Customer No'+','+'Customer Name'+','+'Balance');
                    If CustomerMaster.FindSet() then repeat
                        CustomerMaster.SetAutoCalcFields(CustomerMaster.Balance);
                        TextFileBuilder.AppendLine(CustomerMaster."No."+','+CustomerMaster.Name+','+Format(CustomerMaster.Balance));
                    until CustomerMaster.Next()=0;
                    Tempblob.CreateOutStream(OutStreamData);
                    OutStreamData.WriteText(TextFileBuilder.ToText());
                    Tempblob.CreateInStream(InStreamData);
                    DownloadFromStream(InStreamData,'','','',FileName);
                end;
            }
        }
    }
}

If you look at the above code it is taking required data from customer table and export the data in text file as below.

To get more insight of data type have a look at MS documentation from below link

https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/textbuilder/textbuilder-data-type

Hope this will help you.

Stay tuned for more.