web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Generate Emails using word layout

(1) ShareShare
ReportReport
Posted on by 24
Hi 
 
I am working a AL extension to send a reminder Email to due Invoice in BC. For this I am using Report Object and word layout  generate HTML email. To get the email details I am using customer ledger entries. 
 
IF Customer.FINDFIRST THEN
            repeat
                body := '';
                TotalRmtAmt := 0.00;
 
                newdate := (CALCDATE('<+1D>', TODAY));
 
                CustLedgEntry.SETCURRENTKEY("Customer No.", Open, Positive, "Due Date", "Currency Code");
                CustLedgEntry.SETRANGE(CustLedgEntry."Customer No.", Customer."No.");
                CustLedgEntry.SETRANGE(Open, TRUE);
                CustLedgEntry.SETRANGE("Due Date", newdate);
                CustLedgEntry.SETFILTER(CustLedgEntry."Document Type", '%1', CustLedgEntry."Document Type"::Invoice);
 
                IF CustLedgEntry.FINDFIRST THEN BEGIN
                    REPEAT
                        CustLedgEntry.CALCFIELDS("Amount (LCY)");
                        CustLedgEntry.CALCFIELDS("Remaining Amt. (LCY)");
 
                        TotalRmtAmt += CustLedgEntry."Remaining Amt. (LCY)";
 
                    UNTIL (CustLedgEntry.NEXT = 0);
 
                End;
 
                if not CustLedgEntry.IsEmpty Then begin
 
                    Clear(ReportOutStream);
                    Clear(ReportInStream);
                    Clear(body);
                    Clear(TempBlob);
 
                    TempBlob.CreateOutStream(ReportOutStream);
 
                    PaymentReminderInvoice.SetRunningValues(Customer."No.", newdate, TotalRmtAmt);
 
                    if PaymentReminderInvoice.SaveAs('', ReportFormat::Html, ReportOutStream) then begin
                        TempBlob.CreateInStream(ReportInStream);
 
                        ReportInStream.ReadText(body);
 
                        if Customer."E-Mail" <> '' then begin
                            emailMsg.Create(Customer."E-Mail", 'Invoices Due Tomorrow', body, true);
                            email.Send(emailMsg, Enum::"Email Scenario"::"Send Invoice Reminders");
                        end;
 
                    end;
                end;



 
            UNTIL (Customer.NEXT = 0);
 
 
First Customer received the email proper template 
 
Second customer onwards Return FALSE on below statement
 
   if PaymentReminderInvoice.SaveAs('', ReportFormat::Html, ReportOutStream) then begin
 
There is no data level error on 2nd Customer , I have hard corded 2nd customer and check, then successfully sent the email
 
This issue coming when loop thru customer list
 
please provide a solution for this 
 
Thank you
I have the same question (0)
  • Khushbu Rajvi. Profile Picture
    23,136 Super User 2026 Season 2 on at
    .
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    23,136 Super User 2026 Season 2 on at
    It seems the PaymentReminderInvoice.SaveAs method returns FALSE for customers after the first one due to potential issues with report parameters or data. Ensure all necessary values are set correctly for each customer, and check that TotalRmtAmt is greater than zero before attempting to generate the report. Additionally, clear variables at the start of each loop iteration and consider adding logging to capture any anomalies that could help diagnose the issue.
  • Gerardo Rentería García Profile Picture
    27,613 Super User 2026 Season 2 on at

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 566 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 347 Super User 2026 Season 2

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 327 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans