Sir,
A codeunit is made to create a PDF file (from navision report) & sending mails this pdf as an attachment to specified mail ids.
When we run this codeunit manually It works fine as per the expectation but when we use the Scheduler (NAS) for the same purpose it does not work properly(occasionally).
It creates blank pdf file & attached it into the mail.
Where is the problem ?
Please reply.
Now or Never
0
Comments
Have you checked if you can print the document manually for the mails that went wrong?
Tino Ruijs
Microsoft Dynamics NAV specialist
Thanks for reply.
We are using PDFCreator. When we run the codeunit manually it works fine (for every time) but when we'r using NAS for the same purpose it does not create the actual pdf (as Report output) always. Sometimes it creates a blank pdf file while there is data in the report layout.
Where is the problem ?
kindly address.
I've experienced this a couple of times that pdfcreator is too slow.
Tino Ruijs
Microsoft Dynamics NAV specialist
Yes, I have also the bitter experience on the same. So I'm using SLEEP(120000) & giving the enough time to get the better result.
120000? That's much. That's 120 seconds. I've never needed so much time. Most time I needed at customer site was 8000 I think.
I think it all depends on the server, where you put the generated file and maybe the version of pdfcreator too.
Tino Ruijs
Microsoft Dynamics NAV specialist
The report only takes 2-3 seconds to give the output.
The generated file is stored where the NAS is running.
Today the below code performing well with the NAS \:D/ but I don't know whether it will work properly or not in the next day. :-k
http://mibuso.com/forum/viewtopic.php?f=5&t=18331&start=270
(page 19)
"I usually add code to change the timestamp on the file. the NAV function returns a true if sucessful. If the file is still locked it will return a false.
Add a repeat clause.
While not SETSTAMP(Name,date,time) do
end;"
I have used this many times = works great.
http://mibuso.com/blogs/davidmachanick/
Note : Pdf is generated but it's blank.--- It's not happening always. :-k
As I know the file size of the blank pdf, so is it recommended(if possible) to check the file size first before sending it into the mail attachment & if I find the blank size then I will try to reproduce the pdf again and wait until to get the larger size than the blank pdf.
Here's the Call:
IF NOT CheckFileDone(FullPath,1200) THEN //Wait up to 2 minutes for PDF file to complete
ERROR ('Timeout while waiting for file %1 to complete.',FullPath) //Otherwise, put Timeout message in Logfile
**** And here's the Function ****
*** FIrst, the Parameters ***
Var Name DataType Subtype Length
No FullPath Text 1024
No Timeout Duration
*** Now some other Locals ***
Name DataType Subtype Length
FirstTime DateTime
TheFile File
Opened Boolean
TimedOut Boolean
*** And the Return Variable ***
FileOK Boolean
*** Now the Function itself ***
CheckFileDone(FullPath : Text[1024];Timeout : Duration) FileOK : Boolean
//This annoying little function Checks to see if a File exists AND is DONE, by attempting to OPEN the File for WRITING
//This is the ONLY reliable way to "wait for a file" that is coming from a source external from Navision
//Such as a PDF "Printer", file-format changer, etc.
//In case you're wondering, "EXISTS" does NOT work for this, because the file can "Exist",
//but STILL BE BEING WRITTEN by the 'External Process' !!!!!!!
Timeout := Timeout * 1000; //Time in Milliseconds to wait (enter with SECONDS to wait)
FirstTime := CURRENTDATETIME; //Note the time NOW
TheFile.WRITEMODE(TRUE); //Get ready to ATTEMPT to Open TheFile for WRITING
TimedOut := FALSE;
Opened := FALSE;
WHILE (NOT Opened) AND (NOT TimedOut) DO BEGIN
Opened := TheFile.OPEN(FullPath); //TRUE if File EXISTS, is DONE and CLOSED by external Process
TimedOut := (CURRENTDATETIME - FirstTime > Timeout); //TRUE if tired of waiting...
SLEEP(1);
END;
IF Opened THEN
TheFile.CLOSE; //We really weren't going to actually write to the file, only checking to see IF we COULD
FileOK := NOT TimedOut; //Basically, will return TRUE if the file was done BEFORE Timeout
EXIT(FileOK);