RE: How to change the name of downloaded PDF?
Hi ,
From BC21 there is a event subscriber that allows you to change the Filename from base app Report Selection per report.
In Code unit “Custom Layout Reporting” we can use the eventsubscriber “OnGenerateFileNameOnAfterAssignFileName” to change the File name. The Code will look something like this. In my case I wanted to change the customer Statement File Name.
[EventSubscriber(ObjectType::Codeunit, Codeunit::”Custom Layout Reporting”, ‘OnGenerateFileNameOnAfterAssignFileName’, ”, true, true)]
local procedure OnGenerateFileNameOnAfterAssignFileName(var FileName: Text; ReportID: Integer; Extension: Text; DataRecRef: RecordRef)
var
Customer: Record Customer;
FileNameDate: Text[20];
dotpdfPos: Integer;
PreFileNameLbl: Label ‘Statement for %1 %2 %3’;
Pos: Integer;
LengthText: Integer;
begin
if ReportID = 1316 then begin
Customer.Get(DataRecRef.RecordId);
Pos := Text.StrPos(FileName, ‘as’);
dotpdfPos := Text.StrPos(FileName, ‘.pdf’);
FileNameDate := Text.CopyStr(FileName, Pos, dotpdfPos);
FileName := StrSubstNo(PreFileNameLbl, Customer.”No.”, Customer.Name, FileNameDate);
end;
end;
This Returns a Filename - “Statement for "Customer No." "Customer Name" as of "Start Date" .”