bcquality/microsoft/knowledge/performance/load-common-fields-before-branching-on-case.md
Jesper Schulz-Wedde 2b5550c346
Some checks failed
Validate knowledge index / validate-index (push) Has been cancelled
Validate AL review fixtures / validate-review-fixtures (push) Has been cancelled
Validate frontmatter and structure / validate (push) Has been cancelled
Improve partner onboarding and documentation navigation (#174)
Lead with a complete plugin quick start and add task-oriented usage, troubleshooting, customization, and contribution guides. Preserve the broader plugin framing, correct conflicting contract guidance, support Agents folder reviews, and align repository validation. Convert existing sample references to clickable links without changing knowledge rules.

Co-authored-by: Jesper Schulz-Wedde <jesper.schulzwedde@microsoft.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
2026-09-09 17:31:03 +02:00

1.5 KiB

bc-version domain keywords technologies countries application-area
all
performance
setloadfields
case
conditional
branch
field-loading
al
w1
all

Load common fields before branching on case

Contributions welcome — open a PR to refine or extend this article.

Description

When a known input determines which fields a subsequent record read will use, a single SetLoadFields containing every branch's fields loads unnecessary columns. Build the selection before Get, FindFirst, or FindSet: use SetLoadFields for fields common to every branch, then AddLoadFields for the selected branch. SetLoadFields replaces the current selection, while AddLoadFields preserves it.

Best Practice

Call SetLoadFields with the common fields. In each branch, call AddLoadFields with that branch's normal fields and then perform the record read. This applies only when the discriminator is known before the read; branching on a field from an already-loaded row is too late to tailor that row's initial SQL projection.

See sample: load-common-fields-before-branching-on-case.good.al.

Anti Pattern

A single top-level SetLoadFields enumerating every branch's fields, or a branch-local SetLoadFields that accidentally discards the common selection. Both make the declared load plan differ from the fields the selected path actually uses.

See sample: load-common-fields-before-branching-on-case.bad.al.