web
You’re offline. This is a read only version of the page.
close
Skip to main content
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

I have the same question (0)
  • Verified answer
    Mohana Yadav Profile Picture
    60,967 Super User 2025 Season 2 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

  • Suggested answer
    Govinda Kumar Profile Picture
    2,300 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..

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 4,330

#2
Sumit Singh Profile Picture

Sumit Singh 2,738

#3
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 2,546

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans