mirror of
https://github.com/microsoft/BCQuality.git
synced 2026-08-07 18:06:53 +01:00
Add CMFRT naming conventions, object ID ranges, and patterns documentation
- Introduced guidelines for using the "CMFRT" prefix in object names, fields, and procedures to avoid naming collisions and ensure clarity. - Established rules for object ID ranges to prevent conflicts with other extensions and maintain historical integrity. - Documented best practices and anti-patterns for various coding patterns, including case statements, interface injection, label usage, and validation methods. - Implemented a standards review skill to evaluate AL source changes against CMFRT company standards, ensuring compliance with naming, permissions, and architectural patterns.
This commit is contained in:
parent
d6ac005173
commit
afb1fa2883
53 changed files with 1288 additions and 0 deletions
26
custom/knowledge/patterns/cmfrt-maxstrlen-copystr.md
Normal file
26
custom/knowledge/patterns/cmfrt-maxstrlen-copystr.md
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
---
|
||||
bc-version: [all]
|
||||
domain: patterns
|
||||
keywords: [maxstrlen, copystr, truncation, magic-number, field-length, overflow, string]
|
||||
technologies: [al]
|
||||
countries: [w1]
|
||||
application-area: [all]
|
||||
---
|
||||
|
||||
# CMFRT use MaxStrLen in CopyStr, never a literal length
|
||||
|
||||
## Description
|
||||
|
||||
When CMFRT code truncates a text value to fit a field, the length argument of `CopyStr` must be `MaxStrLen(TargetRecord.TargetField)`, never a numeric literal. The field is the single source of truth for its own length; a hardcoded number silently diverges the moment the field is widened or the code is copied to a field of a different size, producing either needless truncation or a runtime overflow error.
|
||||
|
||||
## Best Practice
|
||||
|
||||
Write `Rec."CMFRT AQ User ID" := CopyStr(UserId(), 1, MaxStrLen(Rec."CMFRT AQ User ID"));`. The expression stays correct through any future field-length change and documents intent: truncate to whatever fits the target.
|
||||
|
||||
See sample: `cmfrt-maxstrlen-copystr.good.al`.
|
||||
|
||||
## Anti Pattern
|
||||
|
||||
`CopyStr(UserId(), 1, 50)` — the literal encodes the field length at the time of writing. Widening the field leaves data truncated at the stale length; narrowing it turns the assignment into a runtime "length exceeds" error that only fires on long values in production.
|
||||
|
||||
See sample: `cmfrt-maxstrlen-copystr.bad.al`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue