Add TransferFields SkipFieldsNotMatchingType guidance - #133
Add TransferFields SkipFieldsNotMatchingType guidance#133Yahya Touil (yahyatouil-dev) wants to merge 1 commit into
Conversation
|
@microsoft-github-policy-service agree |
Jesper Schulz-Wedde (JesperSchulz)
left a comment
There was a problem hiding this comment.
Two correctness gaps and one sample clarification.
|
|
||
| ## Best Practice | ||
|
|
||
| Use `TransferFields(Source)` when matching field definitions are an expected part of the table design. If source and destination fields intentionally have different types, map those fields explicitly and handle the conversion or validation in code. Use `SkipFieldsNotMatchingType = true` only when skipping incompatible fields is an intentional, documented part of the transfer contract. |
There was a problem hiding this comment.
The one-argument overload is not a complete fail-fast replacement here. It defaults InitPrimaryKeyFields to true, silently ignores destination fields with no matching source field number, and cross-extension type mismatches are skipped even when SkipFieldsNotMatchingType is false. Please preserve the intended primary-key behavior and state that required fields, especially cross-extension fields, must be mapped or verified explicitly.
| @@ -0,0 +1,26 @@ | |||
| --- | |||
| bc-version: [all] | |||
There was a problem hiding this comment.
The three-argument overload is available from runtime 4.2 (BC 15.2+), so [all] lets this rule and its bad sample be selected for older targets where the call does not compile. Please use [16..] for the first complete major that guarantees support, or [15..] only if this repository treats BC 15 as 15.2+.
| procedure CopyData(Source: Record "Transfer Source"; var Target: Record "Transfer Target") | ||
| begin | ||
| Target."Entry No." := Source."Entry No."; | ||
| Evaluate(Target."Reference", Source."Reference"); |
There was a problem hiding this comment.
Evaluate is valid here and will fail loudly because its optional return value is omitted, but it performs conversion only; it does not invoke the destination field's OnValidate trigger. Since the article recommends handling conversion or validation, please either say this sample demonstrates conversion only or evaluate into a local Integer and call Target.Validate("Reference", ConvertedReference) when destination validation is required.
What
One knowledge rule: don't use
TransferFields(..., SkipFieldsNotMatchingType: true)as a blanket way to keep two evolving tables transferring without
errors, when the destination actually depends on every source field
being copied.
Why this belongs in BCQuality
TransferFieldsonly errors on a type mismatch when both tables arein the same extension - cross-extension mismatches are already
skipped by default, flag or not. That distinction isn't obvious from
the method signature, and it's exactly the kind of thing where an AI
(or a dev in a hurry) reaches for
SkipFieldsNotMatchingType = trueto make a compile/runtime error go away without noticing a field
silently stopped being copied.
Files
community/knowledge/data-modeling/transferfields-skip-type-mismatch-can-drop-data.md.good.al- explicit field-by-field mapping withEvaluatefor thetype conversion, so a bad value fails loudly instead of vanishing
.bad.al- two tables in the same app,TransferFields(Source, true, true),Referencesilently dropped because it'sCode[20]on one side andIntegeron the otherVerified against
independently against community testing before writing the rule
One concern, one file, community layer.