Repository navigation
knowledge(style): a new procedure that changes the page's current record should take it as var Record - #216
Conversation
…ord should take it as var Record Adds mutating-procedure-for-a-page-caller-takes-var-record with good/bad samples, a worklist cue in al-style-review, and registration in the style review-fixtures override. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Jesper Schulz-Wedde (JesperSchulz)
left a comment
There was a problem hiding this comment.
Reviewed 49ddf8ae46e925ee589c2ea013ff6607723713e3. The stale-buffer guidance is accurate and narrowly scoped to changed fields read/written later in the same page trigger, not display refresh or key-based APIs in general. The var-parameter remedy follows Base Application prior art, preserves page filters/key, and correctly avoids changing already-published signatures or proposing a var-only overload. The explicit minor ceiling and background/API/temporary/other-table carve-outs prevent broader false positives. Exact-head local frontmatter, fixture/contract, skill/schema and knowledge-index/retrieval checks pass. No merge-critical issue found. GitHub validation workflows await approval and should run before merge.
b503249
into
microsoft:main
Summary
AL passes a
Recordparameter by value (a copy) unless it is declaredvar. When a page/pageextension trigger hands a codeunit only a key (Rec."No.") or a by-valueRec, and the procedureGets orModifys its own copy, the trigger'sReckeeps the old field values. Code later in the same trigger that readsRec(a message, aTestField) or writes from it then works on stale data. Neither the compiler nor the analyzers flag this. The page display itself refreshes after the action (OnAfterGetRecord/OnFindRecord, Learn "Actions at runtime"), so the article is limited to stale use ofRecinside the same trigger, or by a non-page caller.What this adds
microsoft/knowledge/style/mutating-procedure-for-a-page-caller-takes-var-record.md, with good/bad samples. It is design guidance (minor) for new procedures that change the record a page/pageextension trigger already holds.var. The callee must not change the page's filters or key on the parameter. If it needs its own filtering, it copies the record or callsSetRecFilteron the copy first.varon them is AS0078 and is covered bybreaking-changes/do-not-change-published-procedure-signatures. Add a new procedure instead: an overload that differs only byvaris rejected (AL0440, verified with AL compiler 30.0).Sales Post via Job Queue).SystemId(APIV2 Sales Orders).RecordIdAPIs (Approvals Mgmt.ApproveRecordApprovalRequest).RetrySending).performance/avoid-cloning-records-before-modify-delete-in-loopscovers.Rec.Getafter the call is context only, not evidence, because re-reading is a common Base Application idiom.al-style-review, and registration in the style review-fixtures override.Evidence
CurrPage.SetSelectionFilter(Rec); codeunit.Run(50000, Rec);example.Codeunit.Run(Number [, var Record]).ReleaseSalesDoc.PerformManualReopen(Rec), andReopen(var SalesHeader)callsModify(true)on the caller's record. Links are pinned to837ef80.Applies to: all BC versions.
Why style: this is guidance on parameter shape. It sits next to
pages-must-not-contain-business-logicandvar-parameters-require-an-addressable-variable.Test plan
validate_frontmatter.py: 0 errors (2 warnings, both in files this PR doesn't touch)Test-KnowledgeIndex.ps1,Test-SkillIndex.ps1,Test-ReviewContract.ps1,Test-KnowledgeRetrieval.ps1Test-ReviewFixtures.ps1: 230 cases, including the-PrepareDirectorydeterministic ranking check🤖 Generated with Claude Code