5041

Collect Every Error, With Payload

error-collection
errorinfo
batch-validation

Collect Every Error, With Payload

The nightly import feeds journal lines into Business Central, and the current pre-check is worse than useless: it dies on the first broken line and reports a bare text message. The operators want the opposite — one pass over the whole batch that reports every defect at once, each one carrying a machine-readable payload (which record, which field, which check) so the client UI can list them and jump straight to the offending line. Your job is that checker.

What you get

The starter ships three objects. Keep all three exactly as given and include them in your submission — the grading tests reference them by name.

  • Table "Import Journal Line": primary key "Batch Code" (Code[20]) + "Line No." (Integer), plus "Item Code" (Code[20]), Quantity (Decimal) and "Unit Cost" (Decimal).
  • Codeunit "Item Registry" with procedure RequireKnownItem(ImportJournalLine: Record "Import Journal Line") — a sealed stand-in for the company's item registry. An "Item Code" starting with GHOST is unregistered: the registry rejects it by raising a collectible error that already carries its full payload — the line's RecordId, the "Item Code" field number, and the custom dimensions Check = UNKNOWN_ITEM, LineNo, and Probe (a fresh token stamped into both the dimension and the message text at call time). A caller that collects errors gathers the rejection and keeps running; a caller that doesn't dies on the spot. Any other item code — including an empty one — passes the registry silently.
  • Codeunit "Registry Probe Log" — a single-instance log the registry reports into: it counts every RequireKnownItem call per line and records the probe token of each rejection. The grading tests read it; your own code never needs to call it.

Requirements

Implement the codeunit named "Import Journal Validator" with one public procedure:

procedure CheckBatch(BatchCode: Code[20]; var Defects: List of [ErrorInfo])
The rest of the statement and 3 hints Unlock with Pro
ALBusiness Central 28.5
Pro
Pro problem

Solve it with Pro

You’re reading the opening of the statement. Pro unlocks the whole problem:

  • The full statement
  • Starter code in the browser editor
  • 10 grading tests, run on Business Central 28.5
  • 3 hints
  • The reference solution

Pro also opens all 92 Pro problems and lifts the daily limits on compile checks and submissions.

$10 / month
or $100 / year
Upgrade
This problem is part of Pro
Pro unlocks the full statement, tests, hints and solution. The code editor works on a computer.
Upgrade