Skip to main content
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

  • Suggested answer
    Nitin Verma Profile Picture
    21,571 Moderator on at
    RE: How to send emails in a Job Queue with a generated report using the Report.SafeAs function

    Great.

  • Suggested answer
    Faith Whitestar Profile Picture
    5 on at
    RE: How to send emails in a Job Queue with a generated report using the Report.SafeAs function

    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

  • Nitin Verma Profile Picture
    21,571 Moderator on at
    RE: How to send emails in a Job Queue with a generated report using the Report.SafeAs function

    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.

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

News and Announcements

Now Available: 2025 Release Wave 2

Quick Links

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,655

#2
Mansi Soni Profile Picture

Mansi Soni 1,574

#3
YUN ZHU Profile Picture

YUN ZHU 1,453 Super User 2025 Season 1

Featured topics

Product updates

Dynamics 365 release plans