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

Change Subject of Notification Email in AL

(0) ShareShare
ReportReport
Posted on by 307

I tried to change the Subject of Notification email as below 

codeunit 50100 MyNotificationDispatcher
{
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Notification Entry Dispatcher", 'OnBeforeCreateMailAndDispatch', '', true, true)]
    local procedure OnBeforeCreateMailAndDispatch(var Notification: Record "Notification Entry")
    var
        Mail: Record Mail;
    begin
        // Get the mail record associated with the notification
        if Mail.Find('-' + Notification."Notification ID") then
        begin
            // Modify the subject of the mail record
            Mail.Subject := 'New Subject';
            Mail.Modify;
        end;
    end;
}
But the Visual Code does not under Notification and Record Mail
pastedimage1677123017913v1.png
Would you like help me to point what I was wrong in the Code.
I also tried another code form link:    
But after publish, the subject is not changed as I am expecting
codeunit 50100 MyNotificationDispatcher
{
    [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 := 'PO Info - New Email Subject';

        if ReportUsage = 6 then begin

            EmailSubject := '6 - New Email Subject';

            IsHandled := true;

        end;

    end;
}

Thanks

I have the same question (0)
  • Suggested answer
    Mohana Yadav Profile Picture
    61,184 Super User 2026 Season 1 on at

    For which documents are you trying to change?

  • Hoang Ng Profile Picture
    307 on at

    I'd like to change: Purchase Order, Purchase Invoice, General Journal, Payment Journal, and some other forms of Third Party.

  • Suggested answer
    Mohana Yadav Profile Picture
    61,184 Super User 2026 Season 1 on at

    you have to know the report usage value of each document type.

    Ex: 6 means Purchase Order.

    You can find them in enum 77 "Report Selection Usage"

    This code should change the email subject of the Purchase Order

    codeunit 50100 MyNotificationDispatcher

    {

       [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

           if ReportUsage = 6 then begin

               EmailSubject := '6 - New Email Subject';

               IsHandled := true;

           end;

       end;

    }

  • Hoang Ng Profile Picture
    307 on at

    I am sorry to let you misunderstand.

    I'd like to change subject of Approval email not sending document function

    pastedimage1677126213386v1.png

    pastedimage1677126262720v3.png

  • Verified answer
    Mohana Yadav Profile Picture
    61,184 Super User 2026 Season 1 on at

    No Problem.

    which version of BC are you using?

    Latest BC version MailSubject also as a parameter for the above subscriber

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Notification Entry Dispatcher", 'OnBeforeCreateMailAndDispatch', '', false, false)]

       local procedure OnBeforeCreateMailAndDispatch(var NotificationEntry: Record "Notification Entry"; var MailSubject: Text; var Email: Text; var IsHandled: Boolean);

       begin

           MailSubject := 'Custom mail subject';

       end;

  • Hoang Ng Profile Picture
    307 on at

    Thanks Yadav,

    Your code worked well.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,965 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,125 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 961 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans