web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Edit PDF file name for posted sales invoice attachments

(0) ShareShare
ReportReport
Posted on by 67

Hi

I have problem with PDF attachment file name for posted sales invoices. 

My invoices are in format: INV/YEAR/NUMER like INV/2022/001.

If I go to "Actions > Attach as PDF" my pdf name will be "001.pdf", instead format "ReportName DocumentType DocumentNo" like "123456 Invoice INV/2022/001". Problem is with characters '/'

in document no. 

I tried to replace all '/' characters with '-' using ConvertStr(), but I couldn't find any good event to subscribe. Every event I found pass fileName or DocumentNo as normal parameter without prefix var, to edit it as reference.

Code is in table 77 "Report Selections" in procedure "SaveDocumentAttachmentFromRecRef".

I tried to use events:

1.table 77 "Report Selections" > "OnBeforeSaveDocumentAttachmentFromRecRef"

2. table 1173 "DocumentAttachment" > "OnBeforeSaveAttachment"

but all pass parameter without prefix 'var'.

Is there any solution to change PDF fileName in code?

I have the same question (0)
  • Nitin Verma Profile Picture
    21,812 Moderator on at

    Hi,

    Please use below Event  from table 1173.

       [EventSubscriber(ObjectType::Table, Database::"Document Attachment", 'OnBeforeInsertAttachment', '', true, true)]

       local procedure OnBeforeInsertAttachment(var DocumentAttachment: Record "Document Attachment")

       begin

           DocumentAttachment."File Name" := 'your file name';

       end;

    Hope it will help you.

    Thanks.

  • Suggested answer
    Amit Baru Profile Picture
    3,041 on at

    Hi,

    I tried to replace all '/' characters with '-' using--> 

    DELCHR Function (Code, Text) function.

    for removing special character from string.

    Regards

    Amit Sharma

    www.erpconsultors.com

    https://www.linkedin.com/in/amit-sharma-94542440/

    Press Yes if info is useful.

  • Alzack18 Profile Picture
    67 on at

    Thank you for response Nitin Verma. This solution won't work because at this moment DocumentAttachment."File Name" have already cutted file name.

    I need to write this line:

    DocumentAttachment."File Name" := ConvertStr(DocumentAttachment."File Name", '/', '-');

    If line should have name like this: "123456 Invoice INV/2022/001" at this scope field DocumentAttachment."File Name" contains " only "001" value.

  • Alzack18 Profile Picture
    67 on at

    Thank you for response Amit Sharma.

    This doesn't solve my problem, but it's helpful.

  • Suggested answer
    IB-29041624-0 Profile Picture
    1,187 Moderator on at

    Maybe you can show us the complete code you have for the trigger you try to use.

    It is often easier to help when we can see the whole picture through the compete code.

  • Alzack18 Profile Picture
    67 on at

    Thank for your response Inge M. Bruvik. My code looks like this. Just like I wrote in previous comment, this solution doesn't work because DocumentAttachemnt."File Name" contains already cutted file name like "001" instead of "123456 Invoice 001".

    All start in page 132 in action "AttachAsPDF".



    codeunit 50149 AttachPDFFileNameValidation
    
    {
    
        [EventSubscriber(ObjectType::Table, Database::"Document Attachment", 'OnBeforeInsertAttachment', '', true, true)]
        local procedure OnBeforeInsertAttachment(var DocumentAttachment: Record "Document Attachment")
        begin
            DocumentAttachment."File Name" := ConvertStr(DocumentAttachment."File Name", '/', '-');
        end;
    
    }

  • Fisher A Profile Picture
    37 on at

    Anything i change on the event OnBeforeInsertAttachment, does not get updated on record...

    i change the name of the file and it still gets inserted with an old name..

  • Suggested answer
    DAnny3211 Profile Picture
    11,421 Super User 2026 Season 1 on at

    hi

    try this event

    [EventSubscriber(ObjectType::table, 1173, 'OnAfterInsertEvent', '', false, false)]
        local procedure ChangeName(var Rec: Record "Document Attachment")
        begin
            if rec."Table ID" = 112 then begin  // this is my condition
                rec."File Name" := 'NewName'; //-> in your case should be: rec. "File Name" := ConvertStr(rec.'File Name','/','-') ;
                rec.Modify()
            end;
        end;

    obviously try to condition the change according to your document and your conditions

    pastedimage1672770564539v1.png

    check my answer if it helped you, thanks

    DANiele

  • Suggested answer
    YUN ZHU Profile Picture
    100,629 Super User 2026 Season 1 on at

    Hi, just adding some info.

    Hope the following can give you some hints.

    How to directly export Report from page (Custom Filename For Report Export)

    https://yzhums.com/21202/

    Thanks.

    ZHU

  • Fisher A Profile Picture
    37 on at

    yes, it works with this event, but i need to have file name changes before it is saved to BC.

    What i am trying to achieve is when user tries to add an attachment, i want to save it to Azure blob storage and in case if there is an error on sending it to Azure storage, user gets an error and has to try adding an attachment again.

    in file name i want to save the full path to Azure blob storage so taht is why i need it to be updated...

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,036 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,179 Super User 2026 Season 1

#3
AndrewThomas81 Profile Picture

AndrewThomas81 828

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans