Rich text – new Data Type

Use the built-in rich text editor to enter data

Rich text editing capabilities improve the user experience by providing an intuitive and easy-to-use way to create and edit content in Business Central.

Microsoft Learn

  1. Create a new AL Project
    Al-Go

2. Create field to capture rich text

fields
{
field(50100; "PTE_Rich Text"; Blob)
{
Caption = 'Rich Text';
}

}


3. Add procedures to the new table extension to retrieve and write the rich text content

procedure SetRichText(NewRichText: Text)
var
    OutStream: OutStream;
begin
    Clear("PTE_Rich Text");
    "PTE_Rich Text".CreateOutStream(OutStream, TEXTENCODING::UTF8);
    OutStream.WriteText(NewRichText);
    Modify();
end;

procedure GetRichText() RichText: Text
var
    TypeHelper: Codeunit "Type Helper";
    InStream: InStream;
begin
    CalcFields("PTE_Rich Text");
    "PTE_Rich Text".CreateInStream(InStream, TEXTENCODING::UTF8);
    exit(TypeHelper.TryReadAsTextWithSepAndFieldErrMsg(InStream, TypeHelper.LFSeparator(), FieldName("PTE_Rich Text")));
end;

4 Add Rich Text on page extension

pageextension 50100 "PTE_Item Variant Card" extends "Item Variant Card"
{
    layout
    {
        addafter(ItemVariant)
        {
            group(PTE_RichText)
            {
                Caption = 'Rich Text';
                field("PTE_Rich Text"; RichText)
                {
                    Caption = 'Variant Rich Text';
                    Multiline = true;
                    ExtendedDataType = RichContent;
                    ApplicationArea = All;
                    trigger OnValidate()
                    begin
                        Rec.SetRichText(RichText);
                    end;
                }
            }
        }
    }

    trigger OnAfterGetRecord()
    begin
        RichText := Rec.GetRichText();        
    end;

    var
    RichText: Text;

}

5 Publish and inspect result


Hope that helps!