Skip to content

knowledge(data-modeling): Init() keeps the primary key; recompute an editable derived field only while unedited - #272

Open
Michael Dieringer (MichaelDieringer) wants to merge 2 commits into
microsoft:mainfrom
Curabis:community-contribution/data-modeling-init-key-and-derived-field
Open

Michael Dieringer (MichaelDieringer) wants to merge 2 commits into
microsoft:mainfrom
Curabis:community-contribution/data-modeling-init-key-and-derived-field

Conversation

@MichaelDieringer

Copy link
Copy Markdown
Contributor

Summary

Two data-modeling mistakes that compile and pass tests on empty data, then fail once real rows exist.

What this adds

  • microsoft/knowledge/data-modeling/init-does-not-reset-primary-key-before-reinsert.md: Record.Init() leaves the primary key alone (Learn: "Primary key and timestamp fields aren't initialized."). A record variable that just read rows, received TransferFields, or was inserted still holds that key. Without Clear, a separate variable, or a new value for the key field(s) that distinguish the new row, Insert reuses the old key and fails. The failure is common with AutoIncrement keys, which Learn says must be blank before insert.
    • Excluded: a variable that has read nothing; the setup singleton if not Get() then begin Init(); Insert(); end;; code that advances "Line No." while "Document Type"/"Document No." stay the same; temporary records.
  • microsoft/knowledge/data-modeling/only-cascade-derived-field-update-when-not-user-overridden.md: an editable derived field (for example "Search Name") that the source field's OnValidate recomputes unconditionally loses whatever the user typed, with no error. Customer, Vendor, Item and Contact guard the recompute with if ("Search Name" = UpperCase(xRec.Name)) or ("Search Name" = '') then. The article explains why the guard stays safe in every xRec state.
  • Wiring: worklist cues in al-data-modeling-review and registration in the data-modeling review-fixtures override. The derived-field cue fires only when the target is shown editable on a page or presented as an alternate/search name.

No Base Application change is asked for

The derived-field article describes existing Base Application behaviour. Some tables, such as Work Center and Machine Center, recompute "Search Name" unconditionally even though the card shows it as editable. The article names them so a reviewer doesn't treat them as a template. It does not ask for them to change, and the cue applies only to new or changed source→target pairs.

Evidence

  • Learn: Record.Init() remarks; AutoIncrement property remarks; system-defined variables (xRec); Code data type.
  • BCApps: links pinned to 837ef80:
    • the Customer/Vendor/Item/Contact guards;
    • the Work Center recompute and card field;
    • CatalogItemManagement;
    • E-Documents EDocRecurrentBatchSend, which sets "Entry No." := 0 after TransferFields;
    • Data Archive DataArchiveMediaField, which sets "Entry No." := 0 after Init().

Applies to: all BC versions.

Why data-modeling: both concern how records and keys are created and kept consistent. They sit next to master-data-must-be-inserted-with-trigger and transferfields-mirrored-fields-must-match-type-and-length.

Test plan

  • validate_frontmatter.py: 0 errors, 0 warnings
  • Test-ReviewFixtures.ps1: passed, 307 cases
  • Test-ReviewContract.ps1: passed
  • Test-KnowledgeRetrieval.ps1: passed
  • An independent pre-review checked every claim and permalink against BCApps 837ef80 and the live Learn pages
  • Samples not compiled for this PR; they are self-contained illustrative objects

🤖 Generated with Claude Code

…editable derived field only while unedited

Adds init-does-not-reset-primary-key-before-reinsert and
only-cascade-derived-field-update-when-not-user-overridden, each with
good/bad samples, a worklist cue in al-data-modeling-review, and
registration in the data-modeling review-fixtures override.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@JesperSchulz Jesper Schulz-Wedde (JesperSchulz) left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The derived-field test expects a finding, but its example only contains a table, while the review rule excludes fields that aren't exposed on a page. A reviewer could follow that rule correctly and still fail the test.

Please add a small page exposing Search Name as editable to both examples, or supply that setup in the test context, and make the article and review rule consistent.

One smaller, non-blocking clarification: temporary records also retain their primary key after Init(). Please narrow that exception to cases that assign a new key before inserting.

…articles

- Both derived-field examples now include a card page that shows
  "Search Name" as an editable field, so the expected finding no longer
  depends on a field the review rule excludes.
- Article and review rule now use the same trigger: the target is shown
  as an editable field on a page of the app. A Caption/ToolTip alone no
  longer qualifies, and a target shown only as non-editable is excluded.
- Init(): temporary records are no longer a blanket exception. They keep
  their key after Init() too, so they are clean only when the code
  assigns a new key before each Insert.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MichaelDieringer

Copy link
Copy Markdown
Contributor Author

Thanks, Jesper. Addressed in 5a5c796:

  • Both derived-field examples now include a small card page that shows Search Name as an editable field, so the expected finding no longer depends on a field the review rule excludes.
  • The article and the review rule now use the same condition: the target is shown as an editable field on a page of the app. A Caption/ToolTip alone no longer qualifies, and a target shown only as non-editable is excluded.
  • Init(): temporary records are no longer an exception by themselves. They keep their key too, so they are clean only when the code assigns a new key before each Insert.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants