Dear Friends,
Need you help in sorting out my issue that I am facing.
I have few payment entries in Payment Journal for few Vendors (Account Type is Vendor in PJ).
Say,
VEND0001
VEND0002
VEND0003
VEND0004
VEND0005
Requirement: I need to send email to Vendors and Vendor Remittance report as attachment in it. I have placed a new option Email Remittance button in action tab of Payment Journal. On a single click email has to trigger for each Vendors with their corresponding Remittance.
Issue: I could able to send mail to Vendors as mentioned in the requirement. But the email attachment for all Vendors contains the Remittance of all the Vendors in new new page instead of attaching the corresponding Remittance to them.
Report Dataitem: Gen. Journal Line
DataItemTableView Property: WHERE(Journal Batch Name=FILTER(AP-CA-PAYM),Journal Template Name=FILTER(PAYMENTS),Account Type=FILTER(Vendor))
Global Variables
Function
LOCAL SendMailToVendWithAttachment(VendNo : Code[20)
locVendor.RESET; locVendor.SETFILTER(locVendor."E-Mail", '%1', '*@*'); locVendor.SETRANGE(locVendor."No.", "Gen. Journal Line"."Account No."); IF locVendor.FINDFIRST THEN BEGIN REPEAT CLEAR(SMTPMail); CLEARLASTERROR; SMTPSetup.GET; PdfDocPath := 'Remittance for ' locVendor.Name '.pdf'; Path := 'C:\Aarvi\PDFPath\Remittance' PdfDocPath; //Path := FilePath PdfDocPath; CLEAR(VendRemittance); VendRemittance.USEREQUESTPAGE(FALSE); VendRemittance.SETTABLEVIEW("Gen. Journal Line"); VendRemittance.SAVEASPDF(Path); SMTPMail.CreateMessage('Company Name',SMTPSetup."User ID", locVendor."E-Mail",'Remittance for ' locVendor.Name ,'',TRUE); SMTPMail.AppendBody('Dear Sir/Madam,'); SMTPMail.AppendBody('
'); SMTPMail.AppendBody('Please find the attachment of remittance herewith.'); SMTPMail.AppendBody('
'); SMTPMail.AppendBody('Regards,'); SMTPMail.AppendBody('
'); SMTPMail.AppendBody('Company Name'); SMTPMail.AppendBody('
'); SMTPMail.AppendBody('
'); SMTPMail.AppendBody('This is a system generated mail. Please do not reply to this email ID.'); SMTPMail.AddAttachment(Path,PdfDocPath); SMTPMail.Send; SLEEP(1000); ERASE(Path); UNTIL locVendor.NEXT = 0; END;
Calling the Function
Gen. Journal Line - OnAfterGetRecord()
SendMailToVendWithAttachment("Gen. Journal Line"."Account No.");
Can anyone tell me what am I missing here in the code?
Thanks in advance, Aarvi.