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

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,708 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,708 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

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,917

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,161 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,025 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans