Skip to content

knowledge(performance): add trigger-only fields to API pages with AddLoadFields - #253

Open
Kilian Seizinger (pri-kise) wants to merge 1 commit into
microsoft:mainfrom
pri-kise:perf-addloadfields-on-api-pages
Open

Kilian Seizinger (pri-kise) wants to merge 1 commit into
microsoft:mainfrom
pri-kise:perf-addloadfields-on-api-pages

Conversation

@pri-kise

Copy link
Copy Markdown
Contributor

Mistake prevented

API and OData pages load only the fields bound to page controls (partial records applied by the platform). A common API pattern binds an API field to a global variable and fills it from Rec in OnAfterGetRecord, for example to convert a currency code or combine address fields. The Rec fields read there are not bound to any control. Each row's first access then triggers a JIT load (an implicit Get), and a concurrent change can make that load fail with "Inconsistent read of field(s)" or "JIT loading of field(s) ... failed".

The compiler and analyzers don't flag this, and the page returns correct data, so a reviewer or an authoring agent misses it. The cost only shows in telemetry and SQL load. We hit exactly this in partner API pages: telemetry reported "JIT loading of field(s): 'Post Code' failed for table: 'Contact'" until Rec.AddLoadFields was added in OnOpenPage.

The article also flags the tempting wrong fix: Rec.SetLoadFields in OnOpenPage. It replaces the platform's layout-based selection, so layout fields that aren't listed become JIT loads.

Evidence

Versions

bc-version: [17..]: partial records and AddLoadFields arrived in BC 2020 release wave 2.

Domain

performance, next to the report counterpart addloadfields-in-report-onpredataitem.md, which covers the same mechanic for report dataitems.

Checks

  • tools/Build-KnowledgeIndex.ps1: the article parses and is indexed.
  • tools/Test-ReviewFixtures.ps1: passed.
  • tools/Test-ReviewContract.ps1: passed.
  • validate_frontmatter.py was not run locally (no Python on this machine); CI will run it.

…LoadFields

API/OData pages load only fields bound to page controls. Fields that only
trigger code reads (typically OnAfterGetRecord filling a variable-bound API
field) are JIT-loaded per row. Recommend Rec.AddLoadFields in OnOpenPage,
as Microsoft's ExpenseAgent API pages do, and flag SetLoadFields there
because it replaces the platform's layout-based selection.
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