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

Notifications

Announcements

No record found.

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
    20,966 Super User 2025 Season 2 on at
    .
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    20,966 Super User 2025 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
    25,390 Most Valuable Professional 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,116

#2
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 764 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 635 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans