Skip to main content

Notifications

Small and medium business | Business Central, N...
Suggested answer

How to change the name of downloaded PDF?

Posted on by Microsoft Employee

Hi all,

I have a concern that when I download report from BC, the report always named after the report name.

pastedimage1615436405615v1.png

For example, I will have Sales - Shipment (1), Sales - Shipment (2), Sales - Shipment (3) and etc.. And my teams spend a lot time to renaming them in their device after downloading the file. If there any ways I can customize the PDF file naming right after downloading from BC? I would like to have the names, for instance, Sales - Shipment_(Posted Sales Shipment."No.").

Thanks in advance!

Categories:
  • Suggested answer
    Hein Kruger Profile Picture
    Hein Kruger 501 on at
    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" .”

  • Suggested answer
    JAngle Profile Picture
    JAngle 33,159 on at
    RE: How to change the name of downloaded PDF?

    You could look at the report selections table and subscribing to OnBeforeSaveReportAsPDF. Worth considering if you choose email it adds the document no. to the file name, which I assume is what you want. If it cannot email it will download the file anyway. It may put the document number in that way

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans