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

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

(0) ShareShare
ReportReport
Posted on by 591

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
    on at
    RE: Add an Email body from Report Selection Email body to Email Job Queue

    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

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