Overview
In the upcoming Business Central 2025 Wave 1 release, Microsoft has introduced a new feature that allows users to preview PDF attachments directly in the web client. Previously, when users clicked on an attachment in Business Central, the file would download and then open in a separate application. With this new enhancement, users can now view attachments seamlessly within the Business Central interface without downloading themExample:
Viewing Email Attachments in Business Central
One
practical use case for this feature is within the "Compose an
Email" page. When adding a file to the Attachments tab,
previously, clicking on the file name would download it. Now, we can add a "View
File" action that enables direct preview in the same window.
Implementation
using Page Extension
Below is an
AL page extension that adds a "View File" action to the
Email Attachments page. This action allows users to preview attachments
without downloading them.
pageextension 69987 "MPA Email Attachments Ext" extends "Email Attachments"
{
actions
{
addlast(Processing)
{
action(ViewFile)
{
ApplicationArea = All;
Caption = 'View File';
Image = View;
trigger OnAction()
var
TenantMedia: Record
"Tenant Media";
FileInStream: InStream;
begin
// Fetch the attachment
from the "Tenant Media" table
TenantMedia.SetAutoCalcFields(Content);
TenantMedia.Get(Rec.Data.MediaId());
if
TenantMedia.Content.HasValue() then begin
TenantMedia.Content.CreateInStream(FileInStream);
// Use the new
feature to open the file in a preview window
File.ViewFromStream(FileInStream, Rec."Attachment Name",
true);
end;
end;
}
}
}
}
o The new function File.ViewFromStream(FileInStream,
Rec."Attachment Name", true); is used.
o This opens the file directly in the
Business Central web client preview window.
Similarly,
Added to Email Scenario Attachments
I have also
applied the same functionality to the Email Scenario Attachments
page.
GitHub Link ViewFile
No comments:
Post a Comment