| Docs Help
  AppSource  
Docs  /  App  /  NAVAX Extension Base  /  Information for Developers

 Text Editor


2026/06/22 • 8 min. to read
The Text Editor can be opened via the EditText and ShowText procedures from the NCEX Text Editor Mgt. codeunit. Several variants (or several overloads) are available for the EditText function. The ShowText function is only for displaying and not for editing a text. The SetPageCaption function can be called before the EditText or ShowText function to set the caption of the editor page. The following examples show different starting situations and possibilities for integrating the text editor.

Save everything in the text field

The text editor can be called e.g. with a variable of the type Text:
procedure EditText(var Text: Text; MaxLineStrLen: Integer; MaxTextLen: Integer; ReadOnly: Boolean) TextModified: Boolean

Parameter

  • Text Specifies the text to be edited.
  • MaxLineStrLen If specified, this can be used to limit the maximum number of characters per line. The text is automatically wrapped when entered in the editor if the length is exceeded. The wrap tries to leave words whole.
  • MaxTextLen If specified, this can be used to limit the maximum number of characters of the entire text.
  • ReadOnly Specifies whether to open the editor in read-only mode. In read-only mode, the text cannot be changed. However, the text can be marked and contents from it can be copied.

Scenario

  • The following example shows the integration of the editor into the Cash Register Sales Slip Text Setup. The table has a text field with a length of 1000 characters:
    ...
    field(10; "Text"; Text[1000])
    {
        DataClassification = CustomerContent;
        Caption = 'Text', Comment = 'DEU="Text"';
    }
    field(15; "Starting Date"; Date)
    {
    ...
    Since a starting date and an ending date can be added to each text line in addition to the text and the text field itself is large enough, the following simple solution was chosen here, which does not split the text into several lines. A line break in the text is still possible. It is important that the text field in the page is set to Editable = false; because in this solution the line breaks (not visible) are also stored in the text field.

Implementation

  • Table
    ...
    procedure EditText(Editable: Boolean)
    var
        NCEXTextEditorMgt: Codeunit "NCEX Text Editor Mgt.";
        TempText: Text;
    begin
        TempText := Text;
        if not NCEXTextEditorMgt.EditText(TempText, 0, MaxStrLen(Text), not Editable) then
            exit;
        Text := CopyStr(TempText, 1, MaxStrLen(Text));
    end;
    ...
    Page
    ...
    field("Text"; Rec."Text")
    {
        ApplicationArea = All;
        ToolTip = 'Specifies the text. Click on the field to edit the text.', Comment = 'DEU="Gibt den Text an. Klicken Sie auf das Feld, um den Text zu bearbeiten."';
        Editable = false;
        AssistEdit = true;
    
        trigger OnAssistEdit()
        begin
            Rec.EditText(CurrPage.Editable());
            CurrPage.Update();
        end;
    }
    ...

Split text over multiple lines

The text editor can also be called with a variable of the type RecordRef:
procedure EditText(RecordRef: RecordRef; TextFieldNo: Integer; var TempBlob: Codeunit "Temp Blob"; ReadOnly: Boolean) TextModified: Boolean

Parameter

  • RecordRef Specifies which table and which records from the table should be loaded into the text editor.

    Important

    Special care must be taken to ensure that the correct filters are set on the RecordRef.
  • TextFieldNo Indicates in which field the text is stored.

    Note

    The maximum number of characters per line (MaxLineStrLen) is determined by the length of the TextFieldNo field in this call. The text is automatically wrapped when entered in the editor if the length is exceeded. The wrap tries to leave words whole.
  • TempBlob Contains the new, edited text.
  • ReadOnly Specifies whether to open the editor in read-only mode. In read-only mode, the text cannot be changed. However, the text can be marked and contents from it can be copied.

Scenario

  • The following example shows a possible integration of the editor into the Extended Text Lines: Since the table "Extended Text Line" contains only the text and the text field with a length of 100 characters is not large enough, the following solution was chosen here, which splits the text over several lines.

Implementation

  • pageextension 50000 "NVX Extended Text Lines" extends "Extended Text Lines"
    {
        actions
        {
            addfirst(Processing)
            {
                action(NVXTextEditorAction)
                {
                    ApplicationArea = All;
                    Caption = 'Text Editor', Comment = 'DEU="Texteditor"';
                    Image = Edit;
                    ToolTip = 'Edit the text in the text editor.', Comment = 'DEU="Bearbeiten Sie den Text im Texteditor."';
    
                    trigger OnAction()
                    var
                        ExtendedTextLine: Record "Extended Text Line";
                        NCEXTextEditorMgt: Codeunit "NCEX Text Editor Mgt.";
                        TempBlob: Codeunit "Temp Blob";
                        RecordRef: RecordRef;
                        InStream: InStream;
                        NextLineNo: Integer;
                        TempText: Text;
                    begin
                        Clear(ExtendedTextLine);
                        ExtendedTextLine.SetRange("Table Name", Rec."Table Name");
                        ExtendedTextLine.SetRange("No.", Rec."No.");
                        ExtendedTextLine.SetRange("Language Code", Rec."Language Code");
                        ExtendedTextLine.SetRange("Text No.", Rec."Text No.");
                        RecordRef.GetTable(ExtendedTextLine);
                        if not NCEXTextEditorMgt.EditText(RecordRef, ExtendedTextLine.FieldNo(Text), TempBlob, not CurrPage.Editable()) then
                            exit;
    
                        ExtendedTextLine.LockTable();
                        ExtendedTextLine.DeleteAll();
                        NextLineNo := 10000;
                        TempBlob.CreateInStream(InStream);
                        while (not InStream.EOS()) do begin
                            Clear(ExtendedTextLine);
                            ExtendedTextLine."Table Name" := Rec."Table Name";
                            ExtendedTextLine."No." := Rec."No.";
                            ExtendedTextLine."Language Code" := Rec."Language Code";
                            ExtendedTextLine."Text No." := Rec."Text No.";
                            ExtendedTextLine."Line No." := NextLineNo;
                            NextLineNo += 10000;
                            InStream.ReadText(TempText);
                            ExtendedTextLine.Text := CopyStr(TempText, 1, MaxStrLen(ExtendedTextLine.Text));
                            ExtendedTextLine.Insert();
                        end;
                    end;
                }
            }
        }
    }

Store text in a blob

Calling the text editor with Codeunit "Temp Blob" without RecordRef is also possible:
procedure EditText(var TempBlob: Codeunit "Temp Blob"; MaxLineStrLen: Integer; MaxTextLen: Integer; ReadOnly: Boolean) TextModified: Boolean

Parameter

  • TempBlob Contains the text to be edited.
  • MaxLineStrLen If specified, this can be used to limit the maximum number of characters per line. The text is automatically wrapped when entered in the editor if the length is exceeded. The wrap tries to leave words whole.
  • MaxTextLen If specified, this can be used to limit the maximum number of characters of the entire text.
  • ReadOnly Specifies whether to open the editor in read-only mode. In read-only mode, the text cannot be changed. However, the text can be marked and contents from it can be copied.

Scenario

  • If the text is to be stored directly to the record (i.e. no splitting to several records) and the solution via a text field is out of question due to the limited field length (depending on the definition max. 2048 characters), the text can also be stored in a blob field. Optionally, another field can be created, which displays a preview of the blob field content. The following example shows a possible solution.

Implementation

  • Table
    ...
    field(50000; "Text Preview"; Text[250])
    {
        DataClassification = CustomerContent;
        Caption = 'Text Preview', Comment = 'DEU="Textvorschau"';
    }
    field(50001; "Text Storage"; Blob)
    {
        DataClassification = CustomerContent;
        Caption = 'Text Storage', Comment = 'DEU="Textspeicher"';
    }
    
    procedure EditText(Editable: Boolean)
    var
        NCEXTextEditorMgt: Codeunit "NCEX Text Editor Mgt.";
        TempBlob: Codeunit "Temp Blob";
        InStream: InStream;
        OutStream: OutStream;
        NewText: Text;
    begin
        CalcFields("Text Storage");
        "Text Storage".CreateInStream(InStream);
        TempBlob.CreateOutStream(OutStream);
        CopyStream(OutStream, InStream);
        if not NCEXTextEditorMgt.EditText(TempBlob, 0, 0, not Editable) then
            exit;
        TempBlob.CreateInStream(InStream);
        InStream.Read(NewText);
        SaveText(NewText);
    end;
    
    procedure SaveText(NewText: Text)
    var
        OutStream: OutStream;
    begin
        "Text Storage".CreateOutStream(OutStream);
        OutStream.Write(NewText);
        "Text Preview" := CopyStr(NewText, 1, MaxStrLen("Text Preview"));
    end;
    ...
    Page
    ...
    field("Text Preview"; Rec."Text Preview")
    {
        ApplicationArea = All;
        ToolTip = 'Specifies the text. Click on the field to edit the text.', Comment = 'DEU="Gibt den Text an. Klicken Sie auf das Feld, um den Text zu bearbeiten."';
        Editable = false;
        AssistEdit = true;
    
        trigger OnAssistEdit()
        begin
            Rec.EditText(CurrPage.Editable());
            CurrPage.Update();
        end;
    }
    ...

Extend the Editor with Custom Actions

If you add custom actions to the text editor that are intended to be visible only in certain areas, you must enable and link them using the SetExtendedOptions function.

Scenario

  • There should be an action Add Table Caption that adds a table caption to the text at the current cursor position. The following example shows one possible solution.

Implementation

  • Table
    table 50000 "Text Editor Options"
    {
        DataClassification = SystemMetadata;
        Caption = 'Text Editor Options', Comment = 'DEU="Texteditor Optionen"';
        TableType = Temporary;
        ReplicateData = false;
    
        fields
        {
            field(1; "Primary Key"; Code[10])
            {
                DataClassification = SystemMetadata;
                Caption = 'Primary Key', Comment = 'DEU="Primärschlüssel"';
            }
            field(2; "Table No."; Integer)
            {
                DataClassification = SystemMetadata;
                Caption = 'Table No.', Comment = 'DEU="Tabellennr."';
            }
        }
    
        keys
        {
            key(Key1; "Primary Key")
            {
            }
        }
    }
    Page Extension
    pageextension 50000 "Text Editor 2" extends "NCEX Text Editor 2"
    {
        actions
        {
            addlast(Processing)
            {
                action(AddTableCaptionAction)
                {
                    ApplicationArea = All;
                    Caption = 'Add Table Caption', Comment = 'DEU="Tabellenbeschriftung hinzufügen"';
                    ToolTip = 'Adds the table caption to the text.', Comment = 'DEU="Fügt die Tabellenbeschriftung zum Text hinzu."';
                    Visible = AddTableCaptionVisible;
                    Enabled = AddTableCaptionEnabled;
                    Image = Add;
    
                    trigger OnAction()
                    var
                        TempTextEditorOptions: Record "Text Editor Options" temporary;
                        AllObjWithCaption: Record AllObjWithCaption;
                        TableCaption: Text;
                    begin
                        ExtendedOptionsRecordRef.SetTable(TempTextEditorOptions);
                        AllObjWithCaption.Get(AllObjWithCaption."Object Type"::Table,TempTextEditorOptions."Table No.");
                        TableCaption := AllObjWithCaption.TableCaption();
                        InsertTextAtCurrentPosition(TableCaption);
                    end;
                }
            }
    
            addlast(Promoted)
            {
                actionref(AddTableCaptionAction_Promoted; AddTableCaptionAction) { }
            }
        }
    
        var
            AddTableCaptionVisible: Boolean;
            AddTableCaptionEnabled: Boolean;
    
        trigger OnOpenPage()
        begin
            AddTableCaptionVisible := (ExtendedOptionsID = Database::"Text Editor Options");
            AddTableCaptionEnabled := not GetReadOnly();
        end;
    }
    Open Editor
    ...
    var
        TempTextEditorOptions: Record "Text Editor Options" temporary;
        NCEXTextEditorMgt: Codeunit "NCEX Text Editor Mgt.";
        ExtendedOptionsRecordRef: RecordRef;
    ...
        NCEXTextEditorMgt.SetPageCaption('TEST');
        Clear(TempTextEditorOptions);
        TempTextEditorOptions."Table No." := Database::Customer;
        TempTextEditorOptions.Insert();
        ExtendedOptionsRecordRef.GetTable(TempTextEditorOptions);
        NCEXTextEditorMgt.SetExtendedOptions(ExtendedOptionsRecordRef);
        if not NCEXTextEditorMgt.EditText(TempBlob, 0, 0, not Editable) then
            exit;
    ...

Copilot

As of Business Central 28, Copilot resp. the Draft with Copilot action is available in the text editor. You can specify system prompts and suggestions for user prompts using the SetCopilotPromptLists function.

Note

  • The text editor automatically adds the following system prompt when MaxTextLen is specified: StrSubstNo('The text must not exceed %1 characters.', MaxTextLen)
  • The variable [NCEX_EditorText] can be specified in the prompt. When you call the action Draft with Copilot, this is replaced with the current text in the editor.

Related information




Submit feedback for
DE|EN Imprint