Oh, TempBlob! What did you do?

The alternative title for this blog post would have been something like… TempBlob, why did you waste my time! Or waste thousands of hours accross our community.

The topics of my blogs tend to be about what happens in the freelance projects I work on, and last week this was two extensions that have a substantial size (1000+ objects) that had to be BC19 Compatible.

BC19 is the first version of Business Central where warnings about obsoleted objects became errors. The most commonly used are TempBlob and Language.

Language

Language is easy. Functions that used to exist in the table moved to a codeunit and the codeunit has the same name.

In both projects doing a Find/Replace on Language: Record with Language: Codeunit was enough.

Unfortunately for those who use Hungarian Notation, You also have to change your variable names.

TempBlob

This one is a lot more difficult. Not because the Codeunit has a Space in the name, but because the nature of the “Blob” field.

In Saas, the Blob field is the only way to create streams and it requires quite a bit of coding around to work with the obsoleted troubles.

The “Fix”

In both projects I fixed it by creating a new table called “TLA TempBlob” where TLA stands for the Three Letter Abbreviation of the partner on AppSource.

This new table looks like this

table 50500 "PTE Blob"
{
    TableType = Temporary;
    DataClassification = ToBeClassified;

fields

{
    field(1; "Primary Key"; Code[1]) { }

    field(2; Blob; Blob) { }
}

keys
{
    key(Key1; "Primary Key")  { Clustered = true; }
}

procedure MoreTextLines(): Boolean
begin

    IF NOT ReadLinesInitialized THEN
        StartReadingTextLines(TEXTENCODING::Windows);

    EXIT(NOT GlobalInStream.EOS);
end;

procedure ReadTextLine(): Text
var
    ContentLine: Text;
begin
    IF NOT MoreTextLines THEN
        EXIT('');

    GlobalInStream.READTEXT(ContentLine);
    EXIT(ContentLine);
end;

procedure ReadAsText(LineSeparator: Text; Encoding: Textencoding) Content: Text

var
    InStream: InStream;
    ContentLine: Text;

begin
    Blob.CREATEINSTREAM(InStream, Encoding);

    InStream.READTEXT(Content);

    WHILE NOT InStream.EOS DO BEGIN
        InStream.READTEXT(ContentLine);
        Content += LineSeparator + ContentLine;
    END;
end;

procedure WriteAsText(Content: Text; Encoding: Textencoding)
var
    OutStr: OutStream;
begin
    CLEAR(Blob);
    IF Content = '' THEN
        EXIT;

    Blob.CREATEOUTSTREAM(OutStr, Encoding);
    OutStr.WRITETEXT(Content);
end;

procedure StartReadingTextLines(Encoding: TextEncoding)

begin
    Blob.CREATEINSTREAM(GlobalInStream, Encoding);
    ReadLinesInitialized := TRUE;
end;

var

    GlobalInStream: InStream;
    GlobalOutStream: OutStream;
    ReadLinesInitialized: Boolean;
    WriteLinesInitialized: Boolean;
}

I know that I am not the only one with this solution. All accross AppSource each App has it’s own new TempBlob table, simply because a Codeunit does not allow the use of the Blob fieldtype as variabletype.

TableType = Temporary

The reason Microsoft obsoleted TempBlob is to prevent people to declare this object without the Temporary tag.

When this happened TableType Temporary did not yet exist.

Now this is the case.

Other Changes

There is one other thing I ran into that I wanted to share.

On a lot of pages, Name 2 and Description 2 are added by Microsoft InVisible. They also removed a few fields.

Removing meant I ran into an issue with AddAfter. This was solved by changing to AddLast, following the Per Tenant Best Practices that you can find elsewhere on this website.

Thank you, with love…

Marije

2 Comments

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.