Skip to main content

Notifications

Small and medium business | Business Central, N...
Answered

Change Subject of Notification Email in AL

Posted on by 295

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

  • Hoang Ng Profile Picture
    Hoang Ng 295 on at
    RE: Change Subject of Notification Email in AL

    Thanks Yadav,

    Your code worked well.

  • Verified answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,125 Super User 2024 Season 2 on at
    RE: Change Subject of Notification Email in AL

    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
    Hoang Ng 295 on at
    RE: Change Subject of Notification Email in AL

    I am sorry to let you misunderstand.

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

    pastedimage1677126213386v1.png

    pastedimage1677126262720v3.png

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,125 Super User 2024 Season 2 on at
    RE: Change Subject of Notification Email in AL

    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
    Hoang Ng 295 on at
    RE: Change Subject of Notification Email in AL

    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
    Mohana Yadav 59,125 Super User 2024 Season 2 on at
    RE: Change Subject of Notification Email in AL

    For which documents are you trying to change?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,151 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,993 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans