Hello reader, in this post I want to talk to you about a novelty that surely did not go unnoticed if you have already started working in BC 23.
I am referring to the possibility of inserting Rich Text fields (formatted text fields) into Business Central pages.
Before the release of BC 23, the only way to insert these fields was to develop a specific control-addin. With the new version of Microsoft Business Central 2023 wave 2, it is now possible to insert these fields on the page, paying attention to certain steps.
Indeed, the structure of the database has not changed, we always have to add a Blob field to the table to which we want to integrate a formatted text. What we need to do is add to the page where we want the formatted text to appear a Text type variable without length or BigText. Let’s see an example that will surely clarify the ideas.
Let’s suppose we want to add a formatted description to the item card page and store it in the table. First of all, we need to extend the Item table by adding a Blob field.
Then we create the page extension for the Item Card page as follows
One thing immediately catches the eye: the Blob field of the table extension was not added, but the ExtDesc variable which is a Text type variable without length. This variable, then, was inserted on the page as a field with the properties Multiline = true and ExtendedDataType = RichContent.
These two properties must be necessarily set, as well as a group (or a factbox, the important thing is that the field is alone) the field with the formatted text must be necessarily inserted.
How to store and display the Blob field of the table? You will have noticed that I created a codeunit with the GetExtendedDescription and SetExtendedDescription function. Let’s see in detail what it is about.
As you can see, in the GetExtendedDescription function, we declare an Instream variable and write its content into the Text variable of the page and in this way we display the content of the field. While, to store any changes in the content, it is enough to declare an Outstream variable, through the Write instruction, write the outstream based on the field of the page and then save it in the table.
The result we get is as follows.
Simple, isn’t it? However, I must give you a piece of advice that applies in general to all Blob fields, don’t abuse them! The more Blob fields you put on the page, the more CalcFields instructions will have to be executed and performance will worsen; therefore, always try to optimize your views with these particular fields.
I hope this post has been useful for the development of your next apps with Microsoft Business Central.