Search code examples
dynamics-business-centraldynamics-al

Blob field not displaying on Business Central page


I've created a table and a page in a BC extension. One of the fields in the table is of type: BLOB. It is not displaying on the page. I've tried to replicate what happens with the 'Work Description' BLOB field in the Sales Header table / Sales Invoice page. Where am I going wrong? See my code below. Thanks in advance for help.

table 50050 LogSheets
{
    fields
    {
        // Various fields...
        field(9; DescriptionOfTasksPerformed; BLOB)
        {
        Caption = 'DescriptionOfTasksPerformed';
        }
    }
    var
    ReadingDataSkippedMsg: Label 'Loading field %1 will be skipped because there was an error when reading the data.\To fix the current data, contact your administrator.\Alternatively, you can overwrite the current data by entering data in the field.', Comment = '%1=field caption';
    
    // Cribbed from Sales Header (table & page) - WorkDescription
    procedure GetTasksDescription() TasksDescription: Text
    var
        TypeHelper: Codeunit "Type Helper";
        InStream: InStream;
    begin
        CalcFields(DescriptionOfTasksPerformed);
        DescriptionOfTasksPerformed.CreateInStream(InStream, TEXTENCODING::UTF8);
        if not TypeHelper.TryReadAsTextWithSeparator(InStream, TypeHelper.LFSeparator(), TasksDescription) then
        Message(ReadingDataSkippedMsg, FieldCaption(DescriptionOfTasksPerformed));
    end;
    
    procedure SetTasksDescription(NewTasksDescription: Text)
    var
        OutStream: OutStream;
    begin
        Clear(DescriptionOfTasksPerformed);
        DescriptionOfTasksPerformed.CreateOutStream(OutStream, TEXTENCODING::UTF8);
        OutStream.WriteText(NewTasksDescription);
        Modify;
    end;
}

page 50051 LogSheetCard
{
    Caption = 'Log Sheet';
    PageType = Document;
    RefreshOnActivate = true;
    SourceTable = LogSheets;
    layout
    {
        area(Content)
        {
            group("LogSheetDetails")
            {
                // Various fields...
            }
            group("Tasks")
            {
                Caption = 'Description of tasks performed';
                field("DescriptionOfTasksPerformed"; Rec.DescriptionOfTasksPerformed)
                {
                    ApplicationArea = Basic, Suite;
                    Importance = Additional;
                    MultiLine = true;
                    ShowCaption = false;
                    ToolTip = 'Description of tasks performed';
                    Editable = true;
                    trigger OnValidate()
                    begin
                        Rec.SetTasksDescription(TasksDescription);
                   end;
                }
            }
        }
    }
    var TasksDescription: Text;
    trigger OnAfterGetRecord()
    begin
        TasksDescription := Rec.GetTasksDescription;
    end;
}

At the bottom of the code above, there's the line: trigger OnAfterGetRecord. This in turn calls GetTasksDescription, which in turn calls CalcFields(DescriptionOfTasksPerformed); This, I believe, is how it’s done in the Sales Header table / Sales Invoice page, and yet still no box is displayed on the page under 'Description of tasks performed' (see below)? I've confirmed that these lines of code are being called by putting Message lines in the relevant procedures. It's a puzzle. screenshot


Solution

  • In your page you set the blob field DescriptionOfTasksPerformed from the table as source of the page field:

    field("DescriptionOfTasksPerformed"; Rec.DescriptionOfTasksPerformed)
    

    But you should use the global variable TasksDescription from the page as the source:

    field("DescriptionOfTasksPerformed"; TasksDescription)