TypeHelper.SetBlobString and TypeHelper.ReadBlob doesn’t exist in Wave 2

During preparation for the #DirectionsEMEA i moved my demos to the Wave 2 and found that TypeHelper.SetBlobString and TypeHelper.ReadBlob doesn’t exist in Wave 2. 

Searched here and found this walkthrough

image

Well, not very helpful.

That is the real solution, that works for me.

image

TypeHelper.SetBlobString

Original code was

				
					procedure SetRestaurantModel(ModelAsText: Text)
    var
        TypeHelper: Codeunit "Type Helper";
        RecordRef: RecordRef;
    begin
        RecordRef.GetTable(Rec);
        TypeHelper.SetBlobString(RecordRef, FieldNo("My Model"), ModelAsText);
        RecordRef.SetTable(Rec);
    end;
				
			

Wave 2 compatible code

				
					procedure SetRestaurantModel(ModelAsText: Text)
    var
        OutStream: OutStream;
    begin
        "My Model".CreateOutStream(OutStream, TextEncoding::UTF8);
        OutStream.Write(ModelAsText);
    end;
				
			

TypeHelper.ReadBlob

Original code was

				
					 procedure GetRestaurantModel(): Text
    var
        TypeHelper: Codeunit "Type Helper";
        BlobFieldRef: FieldRef;
        RecordRef: RecordRef;
    begin
        RecordRef.GetTable(Rec);
        BlobFieldRef := RecordRef.Field(FieldNo("My Model"));
        exit(TypeHelper.ReadBlob(BlobFieldRef));
    end;
				
			

Wave 2 compatible code

				
					    procedure GetRestaurantModel() Content: Text
    var
        TempBlob: Codeunit "Temp Blob";
        InStream: InStream;
    begin
        TempBlob.FromRecord(Rec, FieldNo("My Model"));
        TempBlob.CreateInStream(InStream, TextEncoding::UTF8);
        InStream.Read(Content);
    end;
				
			

Where to search for the inspiration?

Many of the workarounds about how-to-make-your-code-compatible-with-wave-2 could be found in Business Central source files itself. For this current example I got the inspiration from the Late Payment Prediction source code.

Share Post:

Leave a Reply

About Me

DMITRY KATSON

A Microsoft MVP, Business Central architect and a project manager, blogger and a speaker, husband and a twice a father. With more than 15 years in business, I went from developer to company owner. Having a great team, still love to put my hands on code and create AI powered Business Central Apps that just works.

Follow Me

Recent Posts

Tags