---
id: post/yzhums-com/68428
type: post
title: "Dynamics 365 Business Central: Check posting date before posting (preview posting) in the sales and purchase documents – Customization"
summary: 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).
tier: community
language: en
tags:
  - posting date validation
  - event subscriber
  - customization
  - sales documents
  - purchase documents
  - date range check
system: sales
review:
  state: reviewed
  by: opus
  at: "2026-10-26T06:41:37.829Z"
  flags: []
generated:
  at: "2026-10-26T05:51:10.938Z"
  pipeline: 0.2.0
  prompts:
    extract-post: 1
  input_hash: 6bf82ec24874d41a7d47c86a6ed377ab5b7e4a007495057a711e305c79e62245
evidence:
  - kind: blog
    url: https://yzhums.com/68428/
    title: "Dynamics 365 Business Central: Check posting date before posting (preview posting) in the sales and purchase documents – Customization"
    date: "2025-10-17"
    commit: null
    t: null
    quote: null
  - kind: blog
    url: https://yzhums.com/68428/
    title: "Dynamics 365 Business Central: Check posting date before posting (preview posting) in the sales and purchase documents – Customization"
    date: "2025-10-17"
    commit: null
    t: null
    quote: This is just a simple example, you can also use the same method to add other controls, such as required fields, etc.
links:
  learn: []
  objects:
    - object/codeunit/81
    - object/codeunit/91
  features: []
  topics: []
  localizations: []
  videos: []
  posts: []
  guidelines: []
  related:
    - to: post/aardvarklabs-blog/3255
      title: Navigating Namespace Changes in Business Central 28
      label: possibly related
      why: both name Codeunit 81 "Sales-Post (Yes/No)"
      by: code
post_id: "68428"
source_id: yzhums-com
source_name: Dynamics 365 Lab - Yun Zhu
url: https://yzhums.com/68428/
published_at: "2025-10-17T00:33:27.000Z"
author: Yun Zhu
full_text: false
words: 502
quotes:
  - text: This is just a simple example, you can also use the same method to add other controls, such as required fields, etc.
    why_it_matters: Demonstrates that this event subscriber pattern is reusable for implementing additional business rule validations
code_objects_mentioned:
  - codeunit Sales-Post (Yes/No)
  - codeunit Purch.-Post (Yes/No)
  - codeunit ZY Posting Date Handlers
systems:
  - sales
  - purchasing
versions_mentioned: []
preview:
  embeddable: true
  frame_url: null
  image: https://yzhums.com/wp-content/uploads/2025/10/Snipaste_2025-10-16_11-38-26.png
  image_alt: null
  image_w: null
  image_h: null
  site_name: Dynamics 365 Lab
  favicon: https://yzhums.com/wp-content/uploads/2020/08/cropped-logo-3-32x32.png
  probed_at: "2026-10-26T06:13:13.135Z"
---

# Dynamics 365 Business Central: Check posting date before posting (preview posting) in the sales and purchase documents – Customization

[Read the post](https://yzhums.com/68428/) · Dynamics 365 Lab - Yun Zhu (Yun Zhu, MVP) · 2025-10-17 · 502 words · tier community · reviewed (checked by Opus)

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

## 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)"](../../objects/codeunit/81.md)
- [codeunit 91 "Purch.-Post (Yes/No)"](../../objects/codeunit/91.md)
- 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](../../posts/aardvarklabs-blog/3255.md) — 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.
