Error message for NAV e-mail attachment
gadzilla1
Member Posts: 316
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
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
-
Show us some code :shock:0
-
Xypher wrote:Show us some code :shock:
lol I was about to reply the same thing and did a refresh and saw your post.0 -
Why the shock face? lol - I can't take credit for the code, a peer found it online and I used it and it seems to work to the point I encountered errors above. You've probably seen it already, it uses PDF Creator to generate a PDF attachment.0
-
gadzilla I have been doing something similar, with the same code.
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 inIF CONFIRM('send email?') THEN ;
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.0 -
Or you can wait until the file is generated by trying to open the file for writing. If you fail, wait. If you succeeded, all is OK and you can e-mail the file... ;-)0
-
PDFCreator supports automation 'PDFCreator'.clsPDFCreator
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 ?)0 -
Don't just add that trigger though, declare the PDFCreator as 'withevents' and it should show up automatically.0
-
Yes, but for me the trigger is not working at 100% and I needed to use another way how to detect this. It is mainly because if the event is fired when NAV is still busy, the event is not started in NAV...0
-
gadzilla1 wrote:Why the shock face? lol - I can't take credit for the code, a peer found it online and I used it and it seems to work to the point I encountered errors above. You've probably seen it already, it uses PDF Creator to generate a PDF attachment.
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])WaitForFile(strFilePath : Text[1024];intSeconds : Integer) FoundIt : Boolean FOR i := 1 TO intSeconds DO BEGIN IF EXISTS(strFilePath) THEN BEGIN FoundIt := TRUE; EXIT; END; SLEEP(1000); END;
This is the layout of a function I use, but.. it may not work exactly for what you need. As kine said...kine wrote:...Or you can wait until the file is generated by trying to open the file for writing. If you fail, wait...
(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.)0 -
wow I struggled for days with this problem... now here are many good answers.
Xypher I have a variation on your code... I like the idea of your method.WaitForFile(strFilePath : Text[1024];intSeconds : Integer) FoundIt : Boolean start := TIME; WHILE (TIME - intSeconds*1000) < start DO IF EXISTS(strFilePath) THEN EXIT(TRUE); // if we get here then file was not found in allowed time EXIT(FALSE);
no need for SLEEP or Navision Timer
can someone give a little more detail on how to use eReady trigger?0 -
Reinhard wrote: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.)0 -
right...
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.
ieWHILE reportsLeftToPrint DO IF printerReady THEN BEGIN printerReady := FALSE; // generate PDF... // blah blah END;0 -
How do you go about running the PDFCreator function? Like what parameters are you using?
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.0 -
Biggest problem of the event is, that it is called asynchronously and it means, if you have process like "print-attach-send" in one "transaction", you cannot use it, because if there will be some loop or sleep to wait for the trigger, the trigger will be never fired, because NAV must be in "idle state" - doing nothing. And it is hard to do that. I have used to open modal form from my code, and using timer on it testing some flag which will be set in the event. ut sometime the form was open and never closed. It is why I am using right now something like:
File.WriteMode := True; while not File.Open(PdfFile) then sleep(SleepTime); File.Close; //Now the file was created and is free for attaching it to the mail...
You can add some counter to prevent never-ending loop in case of some problems with the PdfPrinter and you are done...[/code]0 -
Try using
REPEAT
UNTIL PDFCreator.cIsConverted;
after REPORT.RUNMODAL
Tested on PDFCreator Version 0.9.5
Harjot0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions


