d.open('Progress #1##############'); TotalCount := InVendLedgEntry.count; repeat CurrCount += 1; d.update(1, strsubstno('%1 of %2', CurrCount, TotalCount)); Vendor.get(InVendLedgEntry."Vendor No."); if InTestEmailAddr <> '' then EmailAddr := InTestEmailAddr else EmailAddr := Vendor."E-Mail"; TempBlob.CreateOutStream(oStr); VendLedgEntry := InVendLedgEntry; VendLedgEntry.SetRecFilter(); clear(VendorPaymentReceipt); VendorPaymentReceipt.SetTableView(VendLedgEntry); if VendorPaymentReceipt.SaveAs('', ReportFormat::Pdf, oStr) then begin AttachmentName := 'PaymentVoucher' + InVendLedgEntry."Document No."; AttachmentName := FileManagement.GetSafeFileName(AttachmentName) + '.pdf'; TempBlob.CreateInStream(iStr); EmailMsg.create( EmailAddr, strsubstno(InEmailSubject, vendor.name, vendor.Contact, InVendLedgEntry."Document No."), strsubstno(InEmailBody, vendor.name, vendor.Contact, InVendLedgEntry."Document No.")); if InccEmailAddr <> '' then EmailMsg.AddRecipient("Email Recipient Type"::Cc, InccEmailAddr); EmailMsg.SetBodyHTMLFormatted(true); EmailMsg.AddAttachment(AttachmentName, 'pdf', istr); //Email.send(EmailMsg); ClearLastError(); If not TryEmailSend(EmailMsg) then error('Email send failed for %1.\\Last Error was %2.\\Error callstack was %3', InVendLedgEntry.RecordId, GetLastErrorText(), GetLastErrorCallStack); end; until InVendLedgEntry.next = 0;
Answers
1. How many records Vendor Ledger entry comes from parent code. VendorPaymentReceipt report processes all incoming records to one PDF.
2. In all cases clear variables, especially streams.