I am trying the auto send a report by mail, i intend to schedule to run this code unit from the scheduler Job.
The issue is SAVEASPDF does not create the report from code unit. Need guidance on how to achieve the result.
REPORT.SAVEASPDF(50038, ‘C:\app\salesVSbudget.pdf’, Location);
SMTPMail.CreateMessage(‘IT-Support’,‘firstname.lastname@example.org’,‘email@example.com’,‘Sales V/S Budget’,’’,TRUE);
Which version of NAV is this?
If in role tailored, then the codeunit is executed on the NAV server. That means the file location is relative to the server, so the file is stored on the server. And if the C:\APP is not available (not created or no permission by the NAV service) then it will not create the file.
But since I don’t know which version, you’re using then I don’t know if this could be an issue. So please always, remember to mention the version. It allows the other users to give a more precise/correct answer. [:)]
Thanks for your reply, the Version is NAV 2009R2, if i run from RTC (copied code to page) the report is generated and mail is send successfully with the attachment. The issue is when I run the code from codeunit with classic client, the file is not created. But since i can run the scheduler with only classic, i want the report to be generated from codeunit.
I seem to remember similar issues with email codeunits and Classic so have you tried using a report and then adding this to the scheduler? Not what you wanted and not the ideal solution but should work.
Yes i did try in the report as well but same issue.
And you are aware that when you run the same code using the classic client, then the C:\app\salesVSbudget.pdf is created locally on the C: drive of the classic client?
Did you try to run it with the debugger? At what point does it fail there?
Yes when code is run with classic client, the file should be created on local drive, i am aware of that.
while debugging, the code REPORT.SAVEASPDF(50038, ‘C:\app\salesVSbudget.pdf’, Location) is executed successfully but when i check the C:\APP folder the file is not created.
Stupid me! [;)] Have not been working much with the classic client the last couple of years.
The SAVEASPDF is not supported on the classic client!
“This function is supported only on client report definition (RDLC) layouts.”
But you should have been getting an error about that.
In the classic client you would have to make some custom code to use a pdf printer driver to save the file to pdf. There are a lot of questions and answers in this forum about how to do that with the classic client already.
Could You Try Saurav Dhyani’s Solution Click Here