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

How to send emails in a Job Queue with a generated report using the Report.SafeAs function

(1) ShareShare
ReportReport
Posted on by 5

Hello dear developers!
I have the following problem when generating a report and sending it.

I have created a job queue with my own codeunit.
This is about the Registered Delivery Reminders (table 5005272 - Issued Deliv. Reminder Header)

I select the records I need and get the email address from the vendor (table 23 Vendor).

The following code snippet gives me a headache:

           RecRef.GetTable(IssuedDeliveryReminderRec);
           TmpBlob.CreateOutStream(OutStr);
           if (Report.SaveAs(5005273, '', Format::Pdf, OutStr, RecRef)) then begin
                            TmpBlob.CreateInStream(InStr);
                            TxtB64 := Cnv64.ToBase64(InStr, true);
                            EmailMsg.Create('mailadress@example.de', 'DeliveryReminder' + IssuedDeliveryReminderRec.Name, DescriptionFromIssuedDeliveryLine, false);
                            EmailMsg.AddAttachment('ReminderMail_' + IssuedDelNo + '' + IssuedDeliveryReminderRec.Name + '.pdf', 'application/pdf', TxtB64);
                            Email.Send(EmailMsg, Enum::"Email Scenario"::"Delivery Reminder");
                        end;

Sending the email to the different vendors works.
The error is that only one report is generated.
However, only one report with one header is generated. All the lines of the selected reports are displayed all together in the rows.
Example:
If I have selected 3 providers, a header is created and all lines of all 3 vendors end up in one report.

I have assumed that the report is generated and sent individually. To be sure I have cleared the used fields:

RecRef.Reset();
Clear(OutStr);
Clear(TxtB64);
Clear(InStr);


Has anyone ever tried something like this and could help me?
Thank you!
Faith

I have the same question (0)
  • Nitin Verma Profile Picture
    21,812 Moderator on at

    Please provide the Vendor filter and send that Vendor records in your Saveas function, you also need to run all your code under your Vendor Repeat...until method.

    Thanks.

  • Suggested answer
    Faith Whitestar Profile Picture
    5 on at

    That was not the reason.

    It was the

    RecRef.GetTable(IssuedDeliveryReminderRec);

    and the following was missing :

    RecRef.SetRecFilter();

    In my execution I also set the reset position incorrectly. These two points helped that my code runs error free

  • Suggested answer
    Nitin Verma Profile Picture
    21,812 Moderator on at

    Great.

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 June Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 702 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 481 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 328 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans