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.
Hello, is it possible to do this in cardpart? I am doing multiple tests and I always get blank.
Thank you
to be honest I did not try. Will check in some time and will let you know
Hi Daniel,
Did you succeed to get a something different as blank in a cardpart ? I have the same problem here…
Thanks for your return.
Hi Kris,
I used CaptionClassTranslate in one solution to export data to excel. I see now that I need to use function DimCaptionClassTranslate from codeunit 343, but I’m not sure do I need to subscribe to
event (OnResolveCaptionClass) like you did, or I need custom function?
if DimFilter[1] ” then begin
EnterFilterInCell(
RowNo,
4,
DimFilter[1],
CaptionMgt.CaptionClassTranslate(GlobalLanguage(), ‘1,3,1’));
end;
Thank you
Hi,
which version of Business Central do you have?
We are now upgrading extension to BC14.04
Is it ok just to copy function DimCaptionClassTranslate from cu343 to my cu and call it, or there are some better way to do this?
Hi Kris,
How can we do this for a page? I have tried to do the same for a card page but all attempts coming up with blank.
Thank you.