Scope sales header attachment cleanup by document type
In the BC 29 source, a Sales Header is identified by Document Type and No., and its Document Attachment records carry the table ID, document number, and attachment document type. A quote and an order can therefore have the same number without being the same owner.
- microsoftlayer
- data-modelingdomain
- 2examples
- 1pull request
Rule on GitHub · microsoft layer · data-modeling · BC 29 · tier official · derived
Description
In the BC 29 source, a Sales Header is identified by Document Type and No., and its Document Attachment records carry the table ID, document number, and attachment document type. A quote and an order can therefore have the same number without being the same owner. Custom cleanup filtered only by table ID and number can delete both owners’ attachments.
Best Practice
For cleanup intended for one sales header, pass its RecordRef to Document Attachment Mgmt.DeleteAttachedDocuments, which applies the owner filters before deleting. If custom filtering is necessary, include the matching document type as well as the table ID and number, and retain any additional filters required by the actual operation and extensions. Do not assume the same dimensions identify every other table’s attachments. Deletion can also affect external storage through installed extensions; verify that lifecycle separately.
See sample: scope-sales-header-attachment-cleanup-by-document-type.good.al.
Anti Pattern
Custom code deletes Document Attachment records for one Sales Header using only Table ID and No., without restricting Document Type. It can remove attachments for a different sales document with the same number. Do not flag a deliberately cross-type operation whose intended scope includes those documents, or code that already constrains the type.
See sample: scope-sales-header-attachment-cleanup-by-document-type.bad.al.
References
- BCApps: Sales Header primary key.
- BCApps: attachment identity and initialization.
- BCApps: attachment management and owner filters.
- BCApps: external storage deletion subscriber.
- External attachment storage: files can be outside the database; do not assume record deletion and external file deletion have identical effects.
Examples
- Good: scope-sales-header-attachment-cleanup-by-document-type.good.al
- Bad: scope-sales-header-attachment-cleanup-by-document-type.bad.al
Names
- table 1173 “Document Attachment” (possibly related: a code span names it)
- codeunit 1173 “Document Attachment Mgmt” (possibly related: a code span names it)
Changed by
- #290 Attachment cleanup by document type, 2026-11-30
From microsoft/BCQuality at 863acaa, MIT License, Copyright (c) 2026 Microsoft Corporation (license).