Hey guys!
I have following problem.
If i go to Finance management--->Periodic Activities--->Reporting E-Mailing---> Report E-mail Queue
Looks like this
Then i select type, which is invoice, in my case, choose report id, name, receiver e-mail etc.
After im done i click Send Email and Status changes from Ready to Error and description says its Report error. After i click on Send Email once again, NAV sends an empty pdf to the receivers e-mail address.
All of the code is under Page Actions and it looks like this:
SendEmail - OnAction()
Window.OPEN(
Text001 +
'@1@@@@@@@@@@@@@@@@@@@@@@@@@\');
Window.UPDATE(1,0);
EmailLog.RESET;
IF EmailLog.FIND('+') THEN
n:=EmailLog.ID
ELSE
n:=0;
EmailQueue.RESET;
EmailQueue.SETRANGE(Send,TRUE);
EmailQueue.SETFILTER("Receiver E-mail",'<>%1','');
TotalRecNo:=EmailQueue.COUNT;
RecNo:=0;
IF EmailQueue.FIND('-') THEN
REPEAT
RecNo+=1;
Window.UPDATE(1,ROUND(RecNo / TotalRecNo * 10000,1));
n+=1;
SalesHeader.RESET;
// ID1:=EmailQueue.ID;
CASE EmailQueue.Type OF
EmailQueue.Type::Invoice:
BEGIN
SalesHeader.RESET;
SalesHeader.SETRANGE("No.",EmailQueue."Document No.");
//02.10.2015 HD.KV HDST1.00->
SalesHeader.FINDFIRST;
IF SalesHeader."Posting No." = '' THEN
RepOK:= REPORT.SAVEASPDF(EmailQueue."Report ID", TEMPORARYPATH + EmailQueue."Document No."+'.pdf', SalesHeader)
ELSE
RepOK:= REPORT.SAVEASPDF(EmailQueue."Report ID", TEMPORARYPATH + SalesHeader."Posting No."+'.pdf', SalesHeader);
//RepOK:= REPORT.SAVEASPDF(EmailQueue."Report ID", TEMPORARYPATH + FORMAT(SESSIONID)+SalesHeader."Posting No."+'.pdf', SalesHeader);
//<-02.10.2015 HD.KV HDST1.00
// MESSAGE(STRSUBSTNO('%1 %2', EmailQueue."Document No.", SalesHeader));
// RepOK:= REPORT.SAVEASPDF(EmailQueue."Report ID", TEMPORARYPATH + EmailQueue."Document No."+'.pdf', SalesHeader)
END;
EmailQueue.Type::"Credit Memo":
BEGIN
SalesHeader.RESET;
SalesHeader.SETRANGE("No.",EmailQueue."Document No.");
//02.10.2015 HD.KV HDST1.00->
SalesHeader.FINDFIRST;
IF SalesHeader."Posting No." = '' THEN
RepOK:= REPORT.SAVEASPDF(EmailQueue."Report ID", TEMPORARYPATH + EmailQueue."Document No."+'.pdf', SalesHeader)
ELSE
RepOK:= REPORT.SAVEASPDF(EmailQueue."Report ID", TEMPORARYPATH + SalesHeader."Posting No."+'.pdf', SalesHeader);
//RepOK:= REPORT.SAVEASPDF(EmailQueue."Report ID", TEMPORARYPATH + FORMAT(SESSIONID)+SalesHeader."Posting No."+'.pdf', SalesHeader);
//<-02.10.2015 HD.KV HDST1.00
END;
EmailQueue.Type::"Posted Invoice":
BEGIN
SalesInvoiceHeader.RESET;
SalesInvoiceHeader.SETRANGE("No.",EmailQueue."Document No.");
//02.10.2015 HD.KV HDST1.00-> RepOK:= REPORT.SAVEASPDF(EmailQueue."Report ID", TEMPORARYPATH + FORMAT(SESSIONID)+EmailQueue."Document No."+'.pdf', SalesInvoiceHeader);
RepOK:= REPORT.SAVEASPDF(EmailQueue."Report ID", TEMPORARYPATH + EmailQueue."Document No."+'.pdf', SalesInvoiceHeader); //02.10.2015 HD.KV HDST1.00
END;
EmailQueue.Type::"Posted Credit Memo":
BEGIN
SalesCrediMemoHeader.RESET;
SalesCrediMemoHeader.SETRANGE("No.",EmailQueue."Document No.");
//02.10.2015 HD.KV HDST1.00-> RepOK:= REPORT.SAVEASPDF(EmailQueue."Report ID", TEMPORARYPATH + FORMAT(SESSIONID)+EmailQueue."Document No."+'.pdf', SalesCrediMemoHeader);
RepOK:= REPORT.SAVEASPDF(EmailQueue."Report ID", TEMPORARYPATH + EmailQueue."Document No."+'.pdf', SalesCrediMemoHeader); //02.10.2015 HD.KV HDST1.00
END;
EmailQueue.Type::"Vendor Reconcilation":
BEGIN
// VendorLedgEntries.RESET;
// VendorLedgEntries.SETRANGE("Vendor No.",EmailQueue."Document No.");
VendorReconcil.SetParams(EmailQueue."Document Date",EmailQueue."Document No.");
RepOK:=VendorReconcil.SAVEASPDF(TEMPORARYPATH + EmailQueue."Document No."+'.pdf'); //02.10.2015 HD.KV HDST1.00
//02.10.2015 HD.KV HDST1.00-> RepOK:=VendorReconcil.SAVEASPDF(TEMPORARYPATH + FORMAT(SESSIONID)+EmailQueue."Document No."+'.pdf');
// CLEAR(VendorReconcil);
// VendorLedgEntries.SETFILTER("Posting Date",'..%1',EmailQueue."Document Date");
// RepOK:= REPORT.SAVEASPDF(EmailQueue."Report ID", TEMPORARYPATH + FORMAT(SESSIONID)+EmailQueue."Document No."+'.pdf', VendorLedgEntries);
END;
EmailQueue.Type::"Customer Reconcilation":
BEGIN
// CustomerLedgEntries.RESET;
// CustomerLedgEntries.SETRANGE("Customer No.",EmailQueue."Document No.");
// CustomerLedgEntries.SETFILTER("Posting Date",'..%1',EmailQueue."Document Date");
CustomerReconcil.SetParams(EmailQueue."Document Date",EmailQueue."Document No.");
RepOK:=CustomerReconcil.SAVEASPDF(TEMPORARYPATH + EmailQueue."Document No."+'.pdf'); //02.10.2015 HD.KV HDST1.00
//02.10.2015 HD.KV HDST1.00-> RepOK:=CustomerReconcil.SAVEASPDF(TEMPORARYPATH + FORMAT(SESSIONID)+EmailQueue."Document No."+'.pdf');//, CustomerLedgEntries);
// RepOK:= REPORT.SAVEASPDF(EmailQueue."Report ID", TEMPORARYPATH + FORMAT(SESSIONID)+EmailQueue."Document No."+'.pdf', CustomerLedgEntries);
// CLEAR(CustomerReconcil);
END;
END;
SmtpMail.CreateMessage(CompanyInfo.Name,CompanyInfo."Smtp Report E-mail",EmailQueue."Receiver E-mail",
EmailQueue."E-mail Subject",EmailQueue."E-mail Subject"{+' ' +EmailQueue."Document No."},FALSE);
IF SendCopyToSender THEN
SmtpMail.AddCC(CompanyInfo."Smtp Report E-mail");
IF RepOK THEN BEGIN
//02.10.2015 HD.KV HDST1.00->
IF (SalesHeader."Posting No." <> '') AND
((EmailQueue.Type = EmailQueue.Type::Invoice) OR (EmailQueue.Type = EmailQueue.Type::"Credit Memo"))
THEN
SmtpMail.AddAttachment(TEMPORARYPATH + SalesHeader."Posting No."+'.pdf','')
ELSE
SmtpMail.AddAttachment(TEMPORARYPATH + EmailQueue."Document No."+'.pdf','');
//SmtpMail.AddAttachment(TEMPORARYPATH +FORMAT(SESSIONID)+EmailQueue."Document No."+'.pdf','');
//<-02.10.2015 HD.KV HDST1.00
SmtpMail.Send();
END;
IF RepOK THEN BEGIN
EmailLog.INIT;
EmailLog.ID:=n;
EmailLog.Type:=EmailQueue.Type;
EmailLog."Report ID":=EmailQueue."Report ID";
EmailLog."Document No.":=EmailQueue."Document No.";
EmailLog."Document Date":=EmailQueue."Document Date";
EmailLog."Receiver E-mail":=EmailQueue."Receiver E-mail";
EmailLog."Sent Time":=CURRENTDATETIME;
EmailLog."Receiver No.":=EmailQueue."Receiver No.";
EmailLog."User ID":=USERID;
EmailLog.INSERT;
EmailQueue.DELETE;
// MESSAGE(FORMAT(RepOK));
END ELSE BEGIN
EmailQueue.Status:=1;
EmailQueue."Error Description":=ReportError;
EmailQueue.MODIFY;
END;
COMMIT;
IF RepOK THEN
//02.10.2015 HD.KV HDST1.00->
IF (SalesHeader."Posting No." <> '') AND
((EmailQueue.Type = EmailQueue.Type::Invoice) OR (EmailQueue.Type = EmailQueue.Type::"Credit Memo"))
THEN
ERASE(TEMPORARYPATH + SalesHeader."Posting No."+'.pdf')
ELSE
ERASE(TEMPORARYPATH + EmailQueue."Document No."+'.pdf');
//ERASE(TEMPORARYPATH +FORMAT(SESSIONID)+EmailQueue."Document No."+'.pdf');
//<-02.10.2015 HD.KV HDST1.00
CLEAR(VendorReconcil);
CLEAR(CustomerReconcil);
RepOK:=FALSE;
UNTIL EmailQueue.NEXT=0;
Window.CLOSE;
CurrPage.UPDATE;
*This post is locked for comments
Hi, Alexander!
It literally just goes from this
to this
So debugger doesnt work as well :/
What exactly that TEMPORARYPATH should show? As i understood a directory where all the temporary NAV reports are kept, right? But how i supposed to know if its right or not? When i add it on the MESSAGE it doesnt show.
Before generating the PDF check if data exists for generating the report.
Hello,
Agree with other members, check where is your application server, becoz TEMPORARYPATH returns the Application server temp path, see the bellow screenshot
Can you post a screenshot with the exact error?
Try to comment all code after "SmtpMail.CreateMessage..." and check your created .pdf file. How it looks on first error, how it looks after secont send button.
if pdf if the same and empty than check you report business logic.
Also i will suggest you to refactor your code, cos now it looks not readible.
You can watch clean code video from Mark about this. www.youtube.com/watch
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,113 Super User 2024 Season 2
Martin Dráb 229,918 Most Valuable Professional
nmaenpaa 101,156