In this post I would like to explore the possibilities to create an email from the Role Tailored client and attach an invoice as a PDF file to the email, unfortunately we have do not have this functional build into our Demo application, but let me show you how this can be do with little effort.
First I suggest you download the fob file which contains the 5 different options I will go through here.
When downloaded the fob file you will see that I have added 5 new actions
1. SendAsPDF(Use of codeunit to rename) recommended solution 2. SendAsPDF(Access to Server needed) 3. SendAsPDF(With Temp file name) 4. SendAsPDF(User prompted to save) 5. SaveAsPDFrecommended solution(if you just want the PDF file)
Let me go through the different options starting from the bottom, since I recommend option 1, but I would also like to share other options for doing this, since these might be valuable for you.
Option 5: SaveAsPDF In this option you will get prompted if you want to open or save the PDF. The PDF file created will be based on the select Invoice in the Posted Sales Invoices List Place
In this option all I do is to have the server create the PDF file for me and use the new download function in NAV 2009 to retrieve the PDF file created on the server.
Option 4: SendAsPDF(User prompted to save) In this option, you will first be prompted to save the file. Here it is important to select to “”SAVE” the PDF file on the disk, to have the correct name of the PDF file. If you select to “OPEN” the PDF filename will be given a temp name.
After you have saved the PDF we now create the email message you will get 3 messages similar to this when this happens:
You get these message because we connect to an external component(Outlook) to the Role Tailored client. It is of course up to you if you want to set this to “Always allow”, but this would remove these messages, the next time you open the Role Tailored client.
When you have allowed these to run, email will be created with the PDF file attached.
In this option all I do is to download the PDF to the client and then use the Mail codeunit to create the email
Option 3: SendAsPDF(With Temp file name) In this option, you will not be prompted to save the PDF file. And the email will be created immediately. This would probably be the preferred compared to downloading this to the user disk, but we will use the PDF file created on the server, and since this file get a TEMP name, like this: “__TEMP__570eb0279b9d4b1fa837caf3a14acbf7” this option is not really good.
Let us look at the option 1 and 2 where this issue is solved.
Option 2: SendAsPDF(Access to Server needed) In this option you will not be prompted to save the file either, but here the end user will need to have access the server folder where the PDF is stored on the server. In some situation you might want this, but for security reasons you might also not want to give this access to the user.
Option 1: SendAsPDF(Use of codeunit to rename) recommended solution Again in this option you will not be prompted to save the PDF file, but the PDF file will be automatically added to the email. In this option we have build a codeunit to rename the TEMP file created on the server, and end user will not need to have access to any folders on the server.
So all in all I recommend option 1 for attaching PDF file to an email. And once again I have made all the code available here, so feel to be explore how I build this. If you feel there is an option that I missed, feel free to leave a commit or use the contact form Email.
Thanks, Claus Lundstrøm, Program Manager, Microsoft Dynamics NAV
I have renamed codeunit 70000 to 50000 and changed the variable in Page 143. When I call option 1 form the RTC there is a error message:
Microsoft Dynamics NAV
No execute permission on object number: 70000 of type: CodeUnit
Can you help me with this?
We are using a classic version of the Invoice report in the RTC (had lots of alignment problems with the RTC version). Is there a way to make this work with the classic version of the report within the RTC?
Is it possible to use segmentation/interaction to send emails with a word document inline in email and pdf files as attachments?
Can we send without opening e mail window
i have try with mail.send; but it is not allowed pass mail.send(True);
anybody have any idea after click the button automatically send to the given name
I tried to call outlook from the RTC however I get an error message:
"There is no default mail client or the current mail client cannot fulfill the messaging request. Please run Microsoft outlook and set it as the default mail client."
I have set outlook as default from within the program, from set your default program in windows, and set program access and computer defaults (this one would not save my preferences oddly).
This works great in RTC. We have enhanced it and now have it as a standard feature in our foundation pack database. I still have clients in classic. Is there similar functionality in classic? The code for RTC does not work in the classic version.
Is there any similar functionality within the classic client?
While this works I am getting a problem with an image in the pdf.
I have an image that is external to the report and called using a url. If I preview/print my report its fine. If i try to use a save as pdf the image doesn't appear.
Is there a trick to getting the image to work with save as pdf?
I have down loaded the code and it is working perfectly for emailing Sales Invoices automatically!! Thanks for this, It is fantastic!
I was just wondering if the same codeunit 70000 can also be used to email Sales Order Confirmation as well?
I changed the code as follows
Cust.GET("Sell-to Customer No.");
IF Cust."Order E Mail Address" <> '' THEN BEGIN
Name := STRSUBSTNO('Order No. %1.pdf, %2', "No.",Cust.Name);
ToFile := Name;
FileName := TEMPORARYPATH + ToFile;
REPORT.SAVEASPDF(REPORT::"Order Confirmation Antala", FileName, SalesHeader);
ToFile := ReportHelper.DownloadToClientFileName(FileName, ToFile);
Mail.NewMessage(Cust."Order E Mail Address",'',Name,'',ToFile,FALSE);
It does everything but the report attached is not pdf? Is there anything I need to change in codeunit 70000 (reportheleper)?
Though I managed to fulfill my requirement with existing codeunit400 but this was the one who inspired me to dig down deep into NAV.
Is there a possibility to check from rdlc whether the report is rendered for print or for PDF. I have to embed pictures if the report is saved as PDF in the print version the pictures shouldn´t be printed.
The Report have to be called with REPORT.SAVEASPDF(ReportId,Filename,Record) because it´s a global function for different reports.