Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

Email invoices

Posted on by Microsoft Employee

when you create a PDF file for an invoice to send to the customer, how can you fix it so when invoice is created and the file should be called the actual invoice nr and if we send as a email how can you fix it comes also the acutal name in the subject?

*This post is locked for comments

  • Suggested answer
    TharangaC Profile Picture
    TharangaC 23,116 on at
    RE: Email invoices

    If you are talking about the emailing a invoice as a PDF and how to change the name of the PDF file then take a look at "Document-Mailing" code unit and its Text Constance.

    These functions are called from

    EmailRecords(ShowRequestForm : Boolean)
    SendRecords(ShowRequestForm,TRUE);
    
    LOCAL SendRecords(ShowRequestForm : Boolean;SendAsEmail : Boolean)
    WITH SalesInvoiceHeader DO BEGIN
      COPY(Rec);
      ReportSelections.SETRANGE(Usage,ReportSelections.Usage::"S.Invoice");
      ReportSelections.SETFILTER("Report ID",'<>0');
      ReportSelections.FIND('-');
      REPEAT
        IF NOT SendAsEmail THEN
          REPORT.RUNMODAL(ReportSelections."Report ID",ShowRequestForm,FALSE,SalesInvoiceHeader)
        ELSE
          SendReport(ReportSelections."Report ID",SalesInvoiceHeader)
      UNTIL ReportSelections.NEXT = 0;
    END;
    
    LOCAL SendReport(ReportId : Integer;VAR SalesInvoiceHeader : Record "Sales Invoice Header")
    ServerAttachmentFilePath := COPYSTR(FileManagement.ServerTempFileName('pdf'),1,250);
    REPORT.SAVEASPDF(ReportId,ServerAttachmentFilePath,SalesInvoiceHeader);
    COMMIT;
    DocumentMailing.EmailFileFromSalesInvoiceHeader(SalesInvoiceHeader,ServerAttachmentFilePath);

    And in the Document-Mailing code unit 

    EmailFileFromSalesInvoiceHeader(SalesInvoiceHeader : Record "Sales Invoice Header";AttachmentFilePath : Text[250])
    EmailFile(AttachmentFilePath,
      SalesInvoiceHeader."No.",
      SalesInvoiceHeader."Bill-to Customer No.",
      SalesInvoiceHeader."Bill-to Name",
      InvoiceTxt);

    And in that Text Constance have following 

    Name   ConstValue
    EmailSubjectCapTxt %1 - %2 %3
    ReportAsPdfFileNameMsg Online Receipt %1 %2.pdf
    InvoiceTxt Invoice
    CrMemoTxt Credit Memos

    And most importantly in this function NAV change the name of the PDF file

    LOCAL EmailFile(AttachmentFilePath : Text[250];PostedDocNo : Code[20];SendEmaillToCustNo : Code[20];SendEmaillToCustName : Text[50];EmailDocName : Text[50])
    AttachmentFileName := STRSUBSTNO(ReportAsPdfFileNameMsg,EmailDocName,PostedDocNo);
    
    WITH TempEmailItem DO BEGIN
      // recSMTP.GET;
      //"From Address" := recSMTP."EMail Address";
      "Send to" := GetToAddressFromCustomer(SendEmaillToCustNo);
      Subject := COPYSTR(
          STRSUBSTNO(
            EmailSubjectCapTxt,SendEmaillToCustName,EmailDocName,PostedDocNo),1,
          MAXSTRLEN(Subject));
      "Attachment File Path" := AttachmentFilePath;
      "Attachment Name" := AttachmentFileName;
      Send(FALSE);
    END;

    If you change the AttachmentFileName then you will be able to change the fie name of the PDF file.

    Hope you would get a idea. 

  • TharangaC Profile Picture
    TharangaC 23,116 on at
  • Verified answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,139 Super User 2024 Season 2 on at
    RE: Email invoices

    Please check this blog

    blogs.msdn.com/.../send-email-with-pdf-attachment-in-nav-2009.aspx

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans