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

Change Subject of Notification Email in AL

(0) ShareShare
ReportReport
Posted on by 297

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
    60,993 Super User 2025 Season 2 on at

    For which documents are you trying to change?

  • Hoang Ng Profile Picture
    297 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
    60,993 Super User 2025 Season 2 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
    297 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
    60,993 Super User 2025 Season 2 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
    297 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

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

#2
Jainam M. Kothari Profile Picture

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

#3
YUN ZHU Profile Picture

YUN ZHU 1,153 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans