I have a report Called Customer Statement (LCY),i need To send the Outstanding Amount to Customer through E-mail with attachment In NAV 2013 R2. but I debug the Code i got this error. plz help
"You cannot call the RequestPage from the OnInitReport Trigger in Report ID “50059” because the RequestPage is not yet initialized.
Page Debugger Watch Value FactBox must close."
CLR.RESET;
CLR.SETRANGE("Customer No.",CustNo);
CLR.SETRANGE(CLR."Document Type",CLR."Document Type" );
IF CLR.FINDFIRST THEN
REPEAT
CLR.CALCFIELDS("Amount (LCY)");
REPORT.SAVEASPDF(50059,'C:\Customer Balance\Custledg.pdf',CLR);
UNTIL (CLR.NEXT=0);
SMTPMailSetup.GET;
CustRec.SETRANGE("No.",CLR."Customer No.");
IF CustRec.FINDFIRST THEN BEGIN
CustEmail := CustRec."E-Mail";
CustLedg.SETTABLEVIEW(CustomerTable);
CLEAR(SMTPMail);
SMTPMail.CreateMessage('','','','Ledger Statement','',TRUE);
SMTPMail.AppendBody('Hi'+ CustomerTable.Name+',');
SMTPMail.AppendBody('<br>');
SMTPMail.AppendBody('Please find attached your Customer Outstanding statement');
SMTPMail.AppendBody('<HR>');
SMTPMail.AppendBody('<Amount>');
SMTPMail.AppendBody('This is a system generated mail. Please do not reply to this mail!');
SMTPMail.AddAttachment('C:\Customer Balance\Custledg.pdf');
SMTPMail.Send;
MESSAGE('Mail sent to Customer %1',CustNo);
END;