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

Announcements

Community site session details

Community site session details

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

Trigger after Purchase Order is released event

(0) ShareShare
ReportReport
Posted on by 307

I found a code to do send email after PO is released

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Release Purchase Document", 'OnAfterReleasePurchaseDoc', '', false, false)]
    local procedure OnAfterReleasePurchaseDoc(var PurchaseHeader: Record "Purchase Header"; PreviewMode: Boolean; var LinesWereModified: Boolean)
    begin
        Commit();
        sendPurchaseOrder(PurchaseHeader);
    end;

    local procedure sendPurchaseOrder(var PurchaseHeader: Record "Purchase Header")
    var

        recOrd: Record "Purchase Header";
    begin
        //Code to send emai

        /////
        Message('Email is send for PO ' + Format(PurchaseHeader."No."));
    end;
}

It showed the message.

But I wonder the line " Commit();" should included or not ? 

Does above code have any risk ?

Is there other better way or the above one is best ?

Thanks

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

    Do you want to release the order if you get any error in email sending process?

    if yes then use commit, if not remove commit

  • Suggested answer
    Govinda Kumar Profile Picture
    2,304 Moderator on at

    Including the "Commit();" line in your code is good idea. It separates the transaction scope of the released document from your email send code which means that if there is an error or failure in sending the email, the purchase order will still be released as Mohana mentioned..

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 2,042 Super User 2026 Season 1

#2
Dhiren Nagar Profile Picture

Dhiren Nagar 1,077 Super User 2026 Season 1

#3
YUN ZHU Profile Picture

YUN ZHU 1,068 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans