Skip to content

miljance/SimpleTextEditor

Repository files navigation

Simple Text Editor for Business Central

A Business Central AL extension that provides a simple HTML-based text editor for editing BLOB fields containing text data. This implementation demonstrates how to create a reusable text editing interface for any BLOB field in Business Central.

Overview

This extension provides a lightweight solution for viewing and editing text stored in BLOB fields. It uses the built-in WebPageViewer control add-in to render an HTML textarea, enabling users to edit large text content directly within Business Central pages.

Components

1. Text Editor Codeunit (TextEditor.Codeunit.al)

The core logic component that handles reading and writing text to BLOB fields.

Key Procedures:

  • EditBlobFieldText(RecordVariant: Variant; FieldNo: Integer) - Opens the text editor in edit mode for the specified BLOB field
  • ViewBlobFieldText(RecordVariant: Variant; FieldNo: Integer) - Opens the text editor in read-only mode
  • ReadBlobText(RecordVariant: Variant; FieldNo: Integer) - Reads text content from a BLOB field
  • WriteBlobText(RecordVariant: Variant; FieldNo: Integer; BlobText: Text) - Writes text content to a BLOB field

Technical Details:

  • Uses Data Type Management and Temp Blob codeunits for generic record handling
  • Supports UTF-8 encoding for international characters
  • Reads and writes text using InStream/OutStream with LF separator
  • Generates HTML textarea with configurable read-only state and maxlength attribute

2. Text Editor Page (TextEditor.Page.al)

A StandardDialog page that hosts the text editing interface.

Features:

  • Uses WebPageViewer user control to render HTML content
  • Dynamic title based on the source record ID
  • Captures changes through callback mechanism
  • Returns edited content when user clicks OK

Initialization:

TextEditor.Init(TitleText, BodyText, GetTextArea(ReadOnly, BodyText));

3. Customer Table Extension (Customer.TableExt.al)

Extends the Customer table with a new BLOB field for storing text comments.

New Field:

  • Field ID: 50100
  • Field Name: "Customer Text"
  • Type: Blob
  • Data Classification: CustomerContent

4. Page Extensions

Customer Card Extension (CustomerCard.PageExt.al)

Adds an "Edit Customer Text" action to the Customer Card page.

Customer List Extension (CustomerListExt.PageExt.al)

Adds an "Edit Customer Text" action to the Customer List page.

Action Implementation:

trigger OnAction()
var
    TextEditor: Codeunit "Text Editor";
begin
    TextEditor.EditBlobFieldText(Rec, Rec.FieldNo("Customer Text"));
end;

How It Works

  1. User Action: User clicks "Edit Customer Text" from Customer List or Customer Card
  2. Read Data: The codeunit reads existing text from the BLOB field using ReadBlobText
  3. Generate HTML: Creates an HTML textarea with the current content
  4. Display Editor: Opens the Text Editor page as a modal dialog
  5. User Edits: User modifies the text in the textarea
  6. Callback: Changes are captured via the WebPageViewer callback mechanism
  7. Save Data: When user clicks OK, the codeunit writes the modified text back to the BLOB field using WriteBlobText

Usage Example

To implement this text editor for any BLOB field in your own extension:

Step 1: Add a BLOB Field

tableextension 50100 "My Table Ext" extends "My Table"
{
    fields
    {
        field(50100; "My Text Field"; Blob)
        {
            Caption = 'My Text Field';
            DataClassification = CustomerContent;
        }
    }
}

Step 2: Add an Action to Open the Editor

pageextension 50100 "My Page Ext" extends "My Page"
{
    actions
    {
        addlast(processing)
        {
            action("Edit My Text")
            {
                Caption = 'Edit My Text';
                ApplicationArea = All;

                trigger OnAction()
                var
                    TextEditor: Codeunit "Text Editor";
                begin
                    TextEditor.EditBlobFieldText(Rec, Rec.FieldNo("My Text Field"));
                end;
            }
        }
    }
}

Step 3: For Read-Only Viewing (Optional)

TextEditor.ViewBlobFieldText(Rec, Rec.FieldNo("My Text Field"));

Technical Requirements

  • Business Central version supporting WebPageViewer control add-in
  • AL Language extension for Visual Studio Code
  • UTF-8 text encoding support

Limitations

  • Maximum text length is determined by the Text data type limit in AL
  • Uses simple textarea without rich text formatting
  • No syntax highlighting or advanced editing features
  • Single-line paste operations use LF separator
  • Has sizing issues when PageType StandardDialog is used

Benefits

  • Reusable: Works with any BLOB field on any table
  • Generic: Uses RecordVariant for maximum flexibility
  • Simple: Minimal dependencies, uses built-in control add-ins
  • UTF-8 Support: Handles international characters correctly
  • Read/Write Modes: Supports both editing and read-only viewing

Namespace

All objects are within the TextEditor.TextEditor namespace to avoid conflicts with other extensions.

Object ID Ranges

  • Tables: 50100
  • Pages: 50100
  • Codeunits: 50100
  • Page Extensions: 50100-50101
  • Table Extensions: 50100

License

This is a sample implementation for educational and development purposes. Feel free to reuse the code with no limitation

Author

Created as a demonstration of BLOB field text editing in Business Central AL.


Last Updated: November 23, 2025

About

Simple Text Editor for Business Central

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages