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

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

(0) ShareShare
ReportReport
Posted on by 629

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;
I have the same question (0)
  • Suggested answer
    Marco Mels Profile Picture
    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

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

#2
YUN ZHU Profile Picture

YUN ZHU 923 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 607

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans