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

Announcements

News and Announcements icon
Community site session details

Community site session details

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

Modify/Change E-Mail Subject

(0) ShareShare
ReportReport
Posted on by 401 User Group Leader

Hello,

is there an integration event or another possibility to modify the standard e-mail subject, when an e-mail is created? For Example to add the externe number from the Sales Header.

Thank you in advance!

Tom

I have the same question (0)
  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    You have the OnBeforeGetEmailSubject in the Document mailing codeunit if it is that you use for sending your mail.

  • T_Mauser Profile Picture
    401 User Group Leader on at

    Jap, I saw that - but I have some troubles to understand how to use it properly.

    The "OnBeforeGetEmailSubject" doesn't return any value - so how can the subject be manipulated? a little nudge would be helpful. 

    procedure GetEmailSubject(PostedDocNo: Code[20]; EmailDocumentName: Text[250]; ReportUsage: Integer) Subject: Text[250]
        var
            EmailParameter: Record "Email Parameter";
            CompanyInformation: Record "Company Information";
            IsHandled: Boolean;
        begin
            IsHandled := false;
            OnBeforeGetEmailSubject(PostedDocNo, EmailDocumentName, ReportUsage, Subject, IsHandled);
            if IsHandled then
                exit(Subject);
    
            if EmailParameter.GetParameterWithReportUsage(PostedDocNo, "Report Selection Usage".FromInteger(ReportUsage), EmailParameter."Parameter Type"::Subject) then
                exit(CopyStr(EmailParameter.GetParameterValue(), 1, 250));
            CompanyInformation.Get();
            if PostedDocNo = '' then
                Subject := CopyStr(
                    StrSubstNo(EmailSubjectPluralCapTxt, CompanyInformation.Name, EmailDocumentName), 1, MaxStrLen(Subject))
            else
                Subject := CopyStr(
                    StrSubstNo(EmailSubjectCapTxt, CompanyInformation.Name, EmailDocumentName, PostedDocNo), 1, MaxStrLen(Subject))
        end;

    Tom

  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    The email subject is referenced by reference not by value in the event handler that takes care of that

            OnBeforeGetEmailSubject(PostedDocNo, EmailDocumentName, ReportUsage, Subject, IsHandled);

    So in the event trigger you set the subject variable to what you want before the event trigger returnes to the publisher.

  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Document-Mailing", 'OnBeforeGetEmailSubject', '', false, false)]
    local procedure OnBeforeGetEmailSubject(PostedDocNo: Code[20]; EmailDocumentName: Text[250]; ReportUsage: Integer; var EmailSubject: Text[250]; var IsHandled: Boolean);
    begin
        Emailsubject :='My new subject';
        IsHandled := true;
    end;

    So this code should do the trick.

  • T_Mauser Profile Picture
    401 User Group Leader on at

    It's working, thank you.

    For me to clarify - what does "referenced by reference" mean? Does it change the variable of the procedure through the parameters?

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

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 612 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 489 Super User 2026 Season 1

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 285 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans