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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

How to run a report, save it as pdf and send to email recipient as a job queue entry that will run every day

(0) ShareShare
ReportReport
Posted on by 5,136

Hi All,

I have a codeunit that performs a saveaspdf on a specific so I can email this report to my email recipients every day.  All is well except the report that I am trying to run has requestpage whereby I want to automate and give it the necessary parameters.  E.g., The request Page for this report has 2 date fields.  I want to automatically assign a value for each of these 2 fields before issuing a SaveasPDF(filename) command to save to a pdf file.  Any thoughts?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at

    Create a function in the report which will assign the value for the parameters and call this function before calling SAVEASPDF>

  • mmv Profile Picture
    11,471 on at

    Hi,

    As mentioned by Suresh, you may add a function in the report to assign the values to the request page variables and call the function before executing SAVEASPDF.

    Best Regards,

    MMV

  • Suggested answer
    Tharanga Chandrasekara Profile Picture
    23,118 on at

    Check this link : community.dynamics.com/.../151165.aspx

    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. 

  • Community Member Profile Picture
    on at

    can u give me the example of the function in the report

    thank you so much

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans