Hi, Readers.
Dynamics 365 Business Central 2025 wave 2 (BC27) is generally available. More details: General Available: Dynamics 365 Business Central 2025 release wave 2 (BC27).
I will continue to test and share some new features that I hope will be helpful. In this post, I would like to talk about Support for new ExtendedDataType value: Document.
This new feature is not yet documented in the Business Central 2025 release wave 2 (BC27) release plan but is mentioned in AL Language extension changelog Version 16.0.
Support for new
Changelog | Visual Studio MarketplaceExtendedDataTypevalue:Document
The ExtendedDataType property forMediaandMediaSetfields now also supports theDocumentvalue. On pages, these fields can only be used on ListPart and CardPart page types, allowing the client to correctly render elements in FactBoxes, such as displaying a PDF as a portrait image.

Regarding ExtendedDatatype Property, we have talked about some topics before.
ExtendedDatatype Property: Sets the extended data type of a control.
- How to set the extended data type of a field (ExtendedDataType Property)
- ‘Concealed’ text field type for sensitive data (New field-level property: MaskType)
- “Contact by Email” in fields with ExtendedDatatype “EMail”
With this wave (BC27), Microsoft adds a new ExtendedDataType value: Documentfor Media and MediaSet fields.
| Value | Available or changed with | Description |
|---|---|---|
| Document | runtime version 16.0 | The client handles the media as a document, optimizing its size for portrait-oriented content like PDFs |
As you might know, there are two ways that you can upload media in Business Central:
- Use a BLOB data typeYou add media to a BLOB data type field on the record. For more information, see BLOB Data Type. (This is the only way to do it before the Media data type is released)
For example, Picture in Company Information:

table 79 “Company Information”:

- Use a Media or MediaSet data type: This way enables you to store media in system tables of the database, and then reference the media from application records. For example, you can:
- Display media with records in list type pages, when the page is viewed in the Tile layout. For more information, see Displaying Data as Tiles.
- Display media on a card type page for a record.
- Display media in a report.
Item Picture: MediaSet Data Type

Customer Picture: Media Data Type

PS: Using the Media or MediaSet data type provides better performance than using a BLOB data type and is more flexible in its design. With a BLOB data type, each time the media is rendered in the client, it’s retrieved from the SQL database server, which requires extra bandwidth and affects performance. With the Media and MediaSet data types, the client uses media ID to cache the media data, which in turn improves the response time for rendering the media in the user interface. More details: Working With Media on Records
Let’s get back to the topic. I created a new media field to the customer table.

I then created a new CardPart page and displayed it on the Customer Card page.


Looks good.

Then I encountered a problem. I thought that the uploaded PDF was saved in the media field, and this new ExtendedDataType: Document supported automatic conversion into an image and display. Actually not. If you only save the format as pdf, the following error will be displayed regardless of whether you specify Mimetype.


I then sought help in the BC Yammer Group, and the answer I got was that this only supports images so far, and I needed to convert the PDF into an image before saving it. More details: Link


At this time we can use codeunit 3110 “PDF Document”.

But then I encountered the second problem. As long as PageNumber is not 1, the following error will be prompted. I’m not sure if this is standard behavior or a current bug, but as of now only the first page of the pdf can be displayed.


A DotNet variable has not been instantiated. Attempting to call System.IO.MemoryStream.Seek in CodeUnit PDF Document Impl.: ConvertToImage

So it seems that this function can only display the first page of the pdf.

Update: This is a bug and Microsoft is currently fixing it.

Test video:
Great, give it a try!!!😁
Source Code: GitHub (Please note that the source code is for reference only, you can improve it according to your own needs)
page 50112 "Customer PDF Preview"
{
Caption = 'Customer PDF Preview';
DeleteAllowed = false;
InsertAllowed = false;
LinksAllowed = false;
PageType = CardPart;
SourceTable = Customer;
layout
{
area(content)
{
field("PDF Preview"; Rec."PDF Preview")
{
ApplicationArea = All;
ShowCaption = false;
}
}
}
actions
{
area(processing)
{
action(ImportPDF)
{
ApplicationArea = All;
Caption = 'Import';
Image = Import;
ToolTip = 'Import a PDF file.';
trigger OnAction()
var
FileManagement: Codeunit "File Management";
FileName: Text;
ClientFileName: Text;
InStr: InStream;
ImageStream: InStream;
TempBlob: Codeunit "Temp Blob";
PDFDocument: Codeunit "PDF Document";
begin
Rec.TestField("No.");
if Rec.Name = '' then
Error(MustSpecifyNameErr);
if Rec."PDF Preview".HasValue() then
if not Confirm(OverridePDFQst) then
exit;
ClientFileName := '';
UploadIntoStream(SelectPDFTxt, '', '', ClientFileName, InStr);
if ClientFileName <> '' then
FileName := FileManagement.GetFileName(ClientFileName);
if FileName = '' then
Error('');
TempBlob.CreateInStream(ImageStream);
PDFDocument.Load(InStr);
PDFDocument.ConvertToImage(ImageStream, Enum::"Image Format"::Png, 1);
Clear(Rec."PDF Preview");
Rec."PDF Preview".ImportStream(ImageStream, FileName);
if not Rec.Modify(true) then
Rec.Insert(true);
end;
}
action(DeletePDF)
{
ApplicationArea = All;
Caption = 'Delete';
Enabled = DeleteExportEnabled;
Image = Delete;
ToolTip = 'Delete the record.';
trigger OnAction()
begin
Rec.TestField("No.");
if not Confirm(DeletePDFQst) then
exit;
Clear(Rec."PDF Preview");
Rec.Modify(true);
end;
}
}
}
trigger OnAfterGetCurrRecord()
begin
SetEditableOnPDFActions();
end;
var
OverridePDFQst: Label 'The existing pdf will be replaced. Do you want to continue?';
DeletePDFQst: Label 'Are you sure you want to delete the pdf?';
SelectPDFTxt: Label 'Select a pdf to upload';
DeleteExportEnabled: Boolean;
MustSpecifyNameErr: Label 'You must specify a customer name before you can import a pdf.';
local procedure SetEditableOnPDFActions()
begin
DeleteExportEnabled := Rec."PDF Preview".HasValue;
end;
}
pageextension 50112 CustomerCardExt extends "Customer Card"
{
layout
{
addbefore(Control149)
{
part(PDFPreviewPart; "Customer PDF Preview")
{
ApplicationArea = All;
SubPageLink = "No." = field("No.");
}
}
}
}
tableextension 50112 CustomerExt extends Customer
{
fields
{
field(50112; "PDF Preview"; Media)
{
DataClassification = CustomerContent;
Caption = 'PDF Preview';
ExtendedDatatype = Document;
}
}
}END
Hope this will help.
Thanks for reading.
ZHU




コメント