Dynamics 365 Business Central: Check posting date before posting (preview posting) in the sales and purchase documents – Customization
A custom codeunit checks whether the posting date on a sales or purchase document is in the current month. If it is not, a confirmation dialog asks the user whether to post anyway, for both regular and preview posting. It uses event subscribers on codeunit 81 Sales-Post (Yes/No) and codeunit 91 Purch.-Post (Yes/No).

post Dynamics 365 Lab
"This is just a simple example, you can also use the same method to add other controls, such as required fields, etc."
Key points
- Standard posting periods (Allow Posting From/To in General Ledger Setup or User Setup) cannot ask for confirmation when the date is outside the current month, so this needs a customization
- Sales uses OnBeforeConfirmPost and OnRunPreviewOnAfterSetPostingFlags in codeunit 81 Sales-Post (Yes/No)
- Purchases use OnBeforeConfirmPost and OnRunPreviewOnBeforePurchPostRun in codeunit 91 Purch.-Post (Yes/No)
- The check uses CalcDate to work out the start and end of the current month from Today (which can be swapped for Workdate), then calls Confirm and raises an empty Error if the user declines
- The same approach can add other checks before posting, such as required fields
Quotes
- “This is just a simple example, you can also use the same method to add other controls, such as required fields, etc.” (Demonstrates that this event subscriber pattern is reusable for implementing additional business rule validations)
AL objects mentioned
As named in the post. A name that matches one object page by exact type and name links to it; the others stay as named.
- codeunit 81 “Sales-Post (Yes/No)”
- codeunit 91 “Purch.-Post (Yes/No)”
- codeunit “ZY Posting Date Handlers”
Not found in BC28-30: codeunit “ZY Posting Date Handlers”.
Possibly related
No source states these links: they share an object, a model read them, or a person found the same subject.
- Navigating Namespace Changes in Business Central 28 — possibly related: both name Codeunit 81 “Sales-Post (Yes/No)”
Context
- Features: posting period validation, preview posting check, event subscriber pattern, date validation, confirmation dialog
Source: Dynamics 365 Lab - Yun Zhu, community blog. Summary, key points and quotes are derived (CONTENT-NOTICE.md); read the original for the full text.