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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Add an Email body from Report Selection Email body to Email Job Queue

(0) ShareShare
ReportReport
Posted on by 666

Hi, 

I have created a new report that is sent as an email as soon as a Cash Receipt Journal has been posted. 
The Customer asked us to add an email body that come from a word report layout. 
I will attach a snippet of my code that is responsible for sending the email. 

Question: How do I replace the email body to be retrieved from a Report Layout instead of hardcoded HTML code?

 [EventSubscriber(ObjectType::Codeunit, Codeunit::"Gen. Jnl.-Post Line", 'OnAfterRunWithoutCheck', '', false, false)]
    local procedure OnAfterRunWithoutCheck(var GenJnlLine: Record "Gen. Journal Line")
    var
        Email: Codeunit Email;
        EmailMessage: Codeunit "Email Message";
        AttachmentInstream: InStream;
        ReportSelection: record "Report Selections";
        IntDocHeader: Record "Int Document Header";
        SalesOrder: Record "Sales Header";
        ReportSelectionCustomerRcpt: Record "Report Selections";
        AttachmentTempBlob: Codeunit "Temp Blob";
        ServerAttachmentFilePath: Text[250];
        ReportSelectionUsage: Enum "Report Selection Usage";
        RecVar: Variant;
        RecordRf: RecordRef;
        ToEmailAddress: Text[250];
        ToEmailSubject: Text[250];
        ToEmailBody: Text[250];
        //Convert Quote to Order
        SalesQuote: Record "Sales Header";
        SalesQuoteToOrder: Codeunit "Sales-Quote to Order";
        //API
        APIManagement: Codeunit "BWA API Management";
        UtopiaAPISetup: Record UtopiaAPISetup;
        //Convert Quote to Order
        Customer: Record customer;
        //IntegrationDocumentLink
        IntBusinessProcess: Codeunit "Int Business Process";
        CustomerLedgEntries: Record "Cust. Ledger Entry";
    begin
                //Dummy report to print, to update when new report is ready.
                ToEmailAddress := ReportSelection.GetEmailAddressExt(ReportSelectionUsage::"Customer payment receipt".AsInteger(), RecordRf, GenJnlLine."Account No.", ReportSelectionCustomerRcpt);
                ToEmailBody := 'Dear Customer, please find attached an acknowledgment of payment receipt';
                if ToEmailAddress <> '' then begin
                    ToEmailSubject := GenJnlLine."Account No." + ' - ' + GenJnlLine.UtopianJobDocNo + ' - ' + FORMAT(ReportSelectionUsage::"Customer payment receipt");
                    RecordRf.Get(GenJnlLine.RecordId);
                    RecordRf.SetTable(GenJnlLine);
                    ReportSelection.BWAGetPdfReportForCust(AttachmentTempBlob, ReportSelectionUsage::"Customer payment receipt", RecordRf, GenJnlLine."Account No.");
                    EmailMessage.Create(ToEmailAddress, ToEmailSubject, ToEmailBody);
                    AttachmentTempBlob.CreateInStream(AttachmentInstream);
                    EmailMessage.AddAttachment('Payment Receipt.pdf', 'pdf', AttachmentInstream);
                    Email.Send(EmailMessage, Enum::"Email Scenario"::"Customer payment receipt");
                end;
            end;
    end;
  • Suggested answer
    Marco Mels Profile Picture
    Microsoft Employee on at

    Hello,

    We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist. If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    www.dynamicsuser.net/.../14

    I will open this up to the community in case they have something to add.

    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

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

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 740 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 570 Super User 2026 Season 2

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 291 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans