Skip to content

fix(PC0036): report SetRecord with a temporary record only when the page reads from the database - #643

Merged
Arthurvdv merged 3 commits into
mainfrom
fix/pc0036-setrecord-database-backed-page
Nov 17, 2026
Merged

Arthurvdv merged 3 commits into
mainfrom
fix/pc0036-setrecord-database-backed-page

Conversation

@Arthurvdv

@Arthurvdv Arthurvdv commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Summary

PC0036 rested on a misunderstanding of Page.SetRecord, as TKapitan pointed out in #368 (the issue stays open until the release ships). SetRecord only positions a page on the record's key; it never hands the record's data to the page. There is no runtime error for a temporary record, and Microsoft's own code uses the pattern freely: an audit of all 324 x.SetRecord(y) call sites in the BC 29 source found 14+ temporary arguments, every one targeting a page whose data source is temporary (SourceTableTemporary = true, a TableType = Temporary source table, or a page serving its own buffer through OnFindRecord). Examples: Item Tracking Summary, Email Accounts, Privacy Notice, Extension Installation, Suggest Price Lines, the Dataverse option lookups from the issue.

The one real pitfall, which motivated the original LinterCop LC0058 request (StefanMaron/BusinessCentral.LinterCop#611), is CustomerCard.SetRecord(TempCustomer) on a page that reads from the database: the temporary data is never shown and the page silently lands on another record. The rule now reports only that case.

What changes

Scenario Before After
temporary record → page over a database table (Customer Card) reported reported
temporary record → CurrPage of a database-backed page (also from a pageextension) reported with an empty receiver name reported
temporary record → page with SourceTableTemporary = true reported not reported
record of a TableType = Temporary table (with or without the keyword) → page over that table reported with keyword only not reported
temporary record → page that declares OnFindRecord (Invt. Order Tracking Lines pattern) reported not reported
temporary record → page without a SourceTable reported not reported
Page.Run / Page.RunModal(Id, TempRec), GetRecord, SetTableView, SetSelectionFilter not reported not reported

Title, message and description are rewritten to describe the positioning semantics and the working alternatives (Page.Run/RunModal with the temporary record, or a SourceTableTemporary page that loads its own data and uses SetRecord to select). Severity stays Warning: the remaining case is a silent wrong-record bug.

Temporary-ness is taken from the keyword or the table type (IsTemporary() in Common); NavTypeKind.CurrPage was added to EnumProvider for the receiver name in the message.

Notes

  • The issue's screenshot shows the diagnostic on a variable without the temporary keyword. That could not be reproduced: the binder derives IRecordTypeSymbol.Temporary from the keyword only on every SDK version checked (12, 16, 17, 18), the analyzer had not changed since it was added, and the existing TempTableTypeWithoutKeyword fixture (the issue's exact shape) passed before and after. It is moot now, because a page over a TableType = Temporary table is never reported.
  • Known limitation (recorded in the rule doc): page triggers are not part of a referenced app's symbols, so a partner app calling SetRecord(Temp) on a referenced database-backed page that serves its data through OnFindRecord is still reported. No such page is a public lookup target in the Microsoft corpus.
  • Docs companion: docs(PC0036): describe SetRecord as positioning and document the temporary-source exceptions alcops.dev#225

Verification

  • dotnet test PC0036: 18 passed (5 of the new NoDiagnostic fixtures failed on the old analyzer, confirming they pin the change).
  • dotnet test ALCops.sln: all green.
  • PlatformCop Release build with ContinuousIntegrationBuild=true (netstandard2.1, net8.0, net10.0): 0 warnings, 0 errors.
  • dotnet format --verify-no-changes, Validate-Rules.ps1: clean.
  • Two /code-review high rounds: no correctness defects; the one rejected finding (an OnFindRecord declared in a pageextension) is impossible because the SDK allows no such trigger on pageextensions, now recorded as an SDK fact.

🤖 Generated with Claude Code

Arthurvdv and others added 3 commits November 17, 2026 18:11
…age reads from the database

Page.SetRecord positions a page on the record's key; it never hands the
record's data to the page. A page whose source is temporary (SourceTableTemporary,
a TableType = Temporary table, or an OnFindRecord override) shows that record
when it loads it itself, so the call is valid there. Only a database-backed page
can never show the temporary data, which is the case the rule now reports.
Temporary-ness is taken from the keyword or the table type, and CurrPage is covered.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…xtension of a temporary-source page

Also fall back to the receiver's source text in the message when the page
instance has no symbol, and record that a pageextension cannot declare
OnFindRecord, so the trigger lookup on the target page misses nothing.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…OnFindRecord

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@Arthurvdv
Arthurvdv merged commit 1ccdef2 into main Nov 17, 2026
53 checks passed
@Arthurvdv
Arthurvdv deleted the fix/pc0036-setrecord-database-backed-page branch November 17, 2026 20:30
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.

1 participant