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

Trigger after Purchase Order is released event

(0) ShareShare
ReportReport
Posted on by 295

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

  • Suggested answer
    Govinda Kumar Profile Picture
    2,211 Moderator on at
    RE: Trigger after Purchase Order is released event

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

  • Verified answer
    Mohana Yadav Profile Picture
    60,199 Super User 2025 Season 1 on at
    RE: Trigger after Purchase Order is released event

    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

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,041 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,856 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans