Hello All,
I've recently implemented some code which allows a user to save a report as a PDF and attach to an e-mail.
However, I believe I am getting an error due to the '.pdf' extension not being read.
The errors I am recieving are occurring on the sales order after clicking Function and Email Confirmation. The errors are 'Send Mail Error Number = 32011' and then 'The operating system cannot find the file c:\se_dem0\temp\Sales Invoice'
In the bold area above, I believe the system is looking for Sales Invoice and should be looking for Sales Invoice.pdf.
Has anyone had this same issue? Any tips, suggestions are greatly appreciated!
Thanks and have a great day. gad1
0
Comments
lol I was about to reply the same thing and did a refresh and saw your post.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
When they asked for code, maybe post the code behind 'Email Notification'
I have two pieces of advice:
It may be easier to show people that when they select PDF creator as teh printer on a report, there is already an option to Email! No reason to try to code it up yourself maybe...
Second, the PDFCreator takes a little bit of TIME to actually create the pdf. So try putting in
right before you try to open the file. This way the system will pause until you press 'Yes' and give the pdf time to be generated. If this turns out to be the problem and you want more help to solve it I have code.
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
this automation object has events that can report back to NAvision if the pdf file was successfully created - define trigger PDFCreator::eReady()
your problem is most likely cause by truncation of filename (what is the length of a variable that holds filename ?)
RIS Plus, LLC
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
The shock face was more or less to show my eyes open wide waiting for the code post
What I can suggest is to create a 'WaitForFile' function either using SLEEP or Navision Timer 1.0 (timer is better because a sleep loop can make what appears to be an infinite loop [short lockup])
This is the layout of a function I use, but.. it may not work exactly for what you need. As kine said...
(It is different because the file may exist and also still may be in use; and access will be denied to read from the file to send as attachment.)
Xypher I have a variation on your code... I like the idea of your method.
no need for SLEEP or Navision Timer
can someone give a little more detail on how to use eReady trigger?
Open the Global/Local variables in the function you use PDFCreator, select the Automation that has 'PDFCreator'.clsPDFCreator, hit Shift-F4 to open the properties page, and finally set WithEvents = Yes. After this Navision will automatically create the event functions provided through the automation.
(Events will always be seen at the very bottom of the code page.)
Basically eReady will trigger after a print process has been completed (and you usually want to clean up the process and revert back to the system's default printer.)
so a good way to use the trigger for this problem might be to have a boolean printerReady, right before you start your print process set it to false. Then in eReady set it to true. My problem is that I was printing multiple reports, but only ending up with the last one... the code was calling the printer before it had time to finish/close the last report.
ie
Reason why I ask is.. what is the filepath/name PDFCreator writing to each time? Do you change per Report? Otherwise you're just overwring the same file over and over.
You can add some counter to prevent never-ending loop in case of some problems with the PdfPrinter and you are done...[/code]
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
REPEAT
UNTIL PDFCreator.cIsConverted;
after REPORT.RUNMODAL
Tested on PDFCreator Version 0.9.5
Harjot