Save report as pdf and send as e-mail

MortenSteengaard
Member Posts: 144
Hi experts,
On Business Central cloud, I have made my own report in my own extension.
I need to add an option for the user to select, if the report should be printed as normal or if it should be sent as an e-mail with a pdf document attched.
I don't want the user to select, where the pdf document should be saved during the process or what file name it should have. When the user selects "Send report as e-mail" on the request page of the report, the e-mail program should pop up with the pdf document attached to a new e-mail, that hasn't been sent yet. Then the user can enter some text and send it manually.
After that the pdf document should only be in the e-mail and not on any disc.
How do I do that?
On Business Central cloud, I have made my own report in my own extension.
I need to add an option for the user to select, if the report should be printed as normal or if it should be sent as an e-mail with a pdf document attched.
I don't want the user to select, where the pdf document should be saved during the process or what file name it should have. When the user selects "Send report as e-mail" on the request page of the report, the e-mail program should pop up with the pdf document attached to a new e-mail, that hasn't been sent yet. Then the user can enter some text and send it manually.
After that the pdf document should only be in the e-mail and not on any disc.
How do I do that?
0
Best Answer
-
Hello @MortenSteengaard ,
Here is an example of how to save a report to PDF and then show the email compose page.pageextension 50120 CustListExtEmail extends "Customer List" { actions { addafter("&Customer") { action(EmailEdit) { Promoted = true; PromotedCategory = Process; PromotedIsBig = true; PromotedOnly = true; Image = Email; ApplicationArea = All; trigger OnAction() begin EmailEdit(Rec."No."); end; } } } local procedure EmailEdit(CustomerId: Code[20]): Text var tmpBlob: Codeunit "Temp Blob"; cnv64: Codeunit "Base64 Convert"; InStr: InStream; OutStr: OutStream; txtB64: Text; format: ReportFormat; email: Codeunit Email; emailMsg: Codeunit "Email Message"; recRef: RecordRef; Customer: Record Customer; begin Customer.Get(CustomerId); Customer.SetRange("No.", CustomerId); recRef.GetTable(Customer); tmpBlob.CreateOutStream(OutStr); if Report.SaveAs(Report::"Customer - Order Summary", '', format::Pdf, OutStr, recRef) then begin tmpBlob.CreateInStream(InStr); txtB64 := cnv64.ToBase64(InStr, true); emailMsg.Create('', '', ''); emailMsg.AddAttachment('OrderSummary.pdf', 'application/pdf', txtB64); email.OpenInEditor(emailMsg); end; end; }
Regards.0
Answers
-
Hello @MortenSteengaard,
You could take a look to this:
https://robertostefanettinavblog.com/2021/01/20/business-central-enhanced-emails/
Regards.0 -
Hi ftornero,
Thanks, but I need help to develop changes to my report.
Best regards,
Morten0 -
Hello @MortenSteengaard ,
Here is an example of how to save a report to PDF and then show the email compose page.pageextension 50120 CustListExtEmail extends "Customer List" { actions { addafter("&Customer") { action(EmailEdit) { Promoted = true; PromotedCategory = Process; PromotedIsBig = true; PromotedOnly = true; Image = Email; ApplicationArea = All; trigger OnAction() begin EmailEdit(Rec."No."); end; } } } local procedure EmailEdit(CustomerId: Code[20]): Text var tmpBlob: Codeunit "Temp Blob"; cnv64: Codeunit "Base64 Convert"; InStr: InStream; OutStr: OutStream; txtB64: Text; format: ReportFormat; email: Codeunit Email; emailMsg: Codeunit "Email Message"; recRef: RecordRef; Customer: Record Customer; begin Customer.Get(CustomerId); Customer.SetRange("No.", CustomerId); recRef.GetTable(Customer); tmpBlob.CreateOutStream(OutStr); if Report.SaveAs(Report::"Customer - Order Summary", '', format::Pdf, OutStr, recRef) then begin tmpBlob.CreateInStream(InStr); txtB64 := cnv64.ToBase64(InStr, true); emailMsg.Create('', '', ''); emailMsg.AddAttachment('OrderSummary.pdf', 'application/pdf', txtB64); email.OpenInEditor(emailMsg); end; end; }
Regards.0 -
Hi ftornero,
Thank you very much! That is great!
Best regards,
Morten0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions