As you probably know, CaptionClass is a nice feature which is used from time to time in the customizations and it is the core of the standard functionality of Business Central. We can see it for example on the pages where dimensions’ names are displayed instead of the number.

In old days, if you wanted to have your own CaptionClass you could do one of two things. First, you could write your own function which would show the caption and declare it in the CaptionClass property. But for some reasons you needed to do that on the table and on the page – if you did it only in one place then it was not properly shown (especially if you wanted to customize the page).

Secondly, was modify the standard Codeunit CaptionManagement by adding code in below function. This is not possible anymore.

The standard is changed

Since the Business Central Release Spring 2019 Codeunit CaptionManagement is completely changed. If you check it now, instead of 400 lines it has… 60. And most of it are the lines with the comments. Except the integration events, you will find there only two procedures. And both are local.

So where is the whole code for CaptionClass and how do you find how does it work now? You will find everything in new Codeunits –  yes multiple Codeunits, not only one. Each of the CaptionClass area (1, 2, 3, 5 and 101) has got its own.

And when looking closer into those objects – there are two functions in each of them. One which is a subscriber to the event which I marked above (OnResolveCaptionClass) and second one which is the code responsible for the CaptionClass.

Our own CaptionClass

To show you how you can create your own CaptionClass I prepared an example. First I created a new table extension to the Item table and I added the fields on the Item Card.

As you can see I added CaptionClass to both my fields.

CaptionClass=’50100,0,0′
And
CaptionClass=’50100,1,0′

Afterwards, I prepared the Codeunit which contains two functions – one with the event subscriber which checks if CaptionArea is 50100, the same as in my table extension.

And second function which checks what is the second parameter in the CaptionClass right after the comma and returns the proper value. Of course, instead of the marked hardcoded values you should use the labels with translations.

And the result you can see in the below screen. On the Item Card I have two fields with my captions.