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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

"OnAfterPostPurchaseDoc: Only First Vendor Invoice Posts — Multiple Vendor Invoices Not Posting

(1) ShareShare
ReportReport
Posted on by 259

Hi All,

I’ve built a custom prepayment module where, based on the vendors in the prepayment lines, separate purchase invoices are created and posted during the Purchase Order posting process. The issue I’m facing is that only the first vendor’s purchase invoice is successfully posted.

For each vendor, I’m calling:

PurchPost.Run(PurchInvoiceHeader);  // on line no. 52

However, it seems that I cannot post multiple purchase invoices during the same OnAfterPostPurchaseDoc event. The second (and any additional) vendor invoices never get posted.

Is there an alternative way to trigger multiple invoice postings safely?

 

Kindly find the attached screenshot.


 

sss.png
I have the same question (0)
  • Suggested answer
    Nour_K Profile Picture
    67 on at
    1. Are you sure the VendorList contains all vendors?
    2. Can you try to clear PurchPost before posting?
     
  • Suggested answer
    OussamaSabbouh Profile Picture
    12,808 Super User 2026 Season 1 on at
    Hello,
     
    You can’t post multiple purchase invoices from inside OnAfterPostPurchaseDoc. Calling PurchPost.Run inside that event causes recursive posting, so only the first invoice succeeds.
     
    To fix it, move the posting outside the event:
     
    either a custom action that posts all vendor invoices one-by-one,
     
    or create them in the event and post later (job queue / separate codeunit).
     
    Regards,
    Oussama Sabbouh
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    22,128 Super User 2026 Season 1 on at
    Don’t post multiple purchase invoices inside OnAfterPostPurchaseDoc — that posting context cannot safely run PurchPost.Run more than once. Instead, use the event only to create the invoices and store them in a buffer table. Then post them afterwards using a separate codeunit that loops through the buffered invoices and calls PurchPost.Run on each one separately.

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

#2
YUN ZHU Profile Picture

YUN ZHU 1,158 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 533 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans