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...
Answered

Modify/Change E-Mail Subject

(0) ShareShare
ReportReport
Posted on by 397 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
    Inge M. Bruvik Profile Picture
    1,105 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
    397 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
    Inge M. Bruvik Profile Picture
    1,105 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
    Inge M. Bruvik Profile Picture
    1,105 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
    397 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

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 3,143

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,694 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,067 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans