As you can only have a maximum length of 250 characters for a text field in NAV tables, it is often the need to store longer text related to a record.
I also wrote about a workaround to something related to this, you can find the post here: Extended Comments in NAV
Another possibility is to use a BLOB field. I used it also in this post to attach files to records. (even if in that case it is better to use the built in NAV datatypes Media and MediaSet.)
Let’s see now how we can use a BLOB field to read and write text data. The text in this case can be of any length, as you can see in this example:
For showing the concept, I created a test table(with a BLOB field) and two pages: one list page with the records and one StandardDialog page with a Text field based on a global variable (unlimited text).
On the List page I wrote code in trigger OnDrillDown of the BLOB field to read data from it, open the StandardDialog page to enter or change the text and then, if the text was modified, to write the new text into the BLOB field:
Description - OnDrillDown() CALCFIELDS(Description); Description.CREATEINSTREAM(InStr); BinaryReader := BinaryReader.BinaryReader(InStr,Encoding.UTF8); IF NOT ISNULL(BinaryReader) THEN BEGIN //read value from BLOB field IF BinaryReader.BaseStream.Length > 0 THEN MyText := BinaryReader.ReadString; BinaryReader.Close; END; InputLongTextTest.SetText(MyText); IF InputLongTextTest.RUNMODAL = ACTION::OK THEN BEGIN NewText := InputLongTextTest.GetText; IF NewText <> MyText THEN BEGIN //write value to BLOB field CLEAR(Description); Description.CREATEOUTSTREAM(OutStr); BinaryWriter := BinaryWriter.BinaryWriter(OutStr,Encoding.UTF8); BinaryWriter.Write(NewText); BinaryWriter.Close; MODIFY; END; END;
And in the StandardDialog page there is code (two global functions) only to get/set the text global variable:
SetText(pMyText : Text) MyText := pMyText; GetText() : Text EXIT(MyText);
This is only a small example of how you can read and write from/to a BLOB field from a technical perspective. It is not ready to use functionality, but you can use the example to build what you need based on it. I wonder though how can we do this in AL Extensions v2, without dot net interop…
I also found an interesting post for reading/writing images to BLOB field, you can read it here:
Binary data with NAV Web Service
You can also download the sample objects used in my example from GitHub
file name: ReadWriteTextBlobNavSampleFilesCAL.txt
UPDATE 22/01/2020: Wrote a new post about how you can Read/Write Text Data From/To multiple BLOB Fields in a Generic Way, please check it out here:
https://andreilungu.com/read-write-text-from-to-blob-fields-generic-way-nav/
this is a very nice example. i have learnt alot. i was wondering how can you do the same with pictures stored in a blob field and subtype bitmap.
Hi, thanks for the comment. Please see this post for image handling with BLOB field:
https://www.kauffmann.nl/2012/04/04/binary-data-with-nav-web-service/
Also, please note that you should use Media/MediaSet fields for handling images:
https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/media/media-data-type