5039

Errors That Fix Themselves

errorinfo
actionable-errors
error-collection

Errors That Fix Themselves

Every promo season the reward-voucher desk drowns in tickets: the redemption batch stops with "something went wrong", the operator guesses at the cause, retries, gives up and calls support. A modern Business Central error does better — it says what happened in one line, explains the remedy, carries the repair parameters in a machine-readable payload, and offers a button that performs the repair on the spot. You will build a redemption routine whose every error can fix itself.

What you get

The starter ships two tables. Keep both exactly as given and include them in your submission — the grading tests seed and read them by name.

  • Table "Reward Voucher": primary key "Voucher Code" (Code[20]), plus Amount (Decimal), "On Hold" (Boolean) and Redeemed (Boolean).
  • Table "Voucher Setup": primary key "Primary Key" (Code[10]), plus "Max Voucher Amount" (Decimal). The setup is the single record whose primary key is empty — the tests always seed it before calling your code.

Requirements

Implement the codeunit named "Voucher Redemption" with one public procedure:

procedure Redeem(VoucherCode: Code[20])

And the codeunit named "Voucher Repair" with two public procedures:

procedure ReleaseHold(FailureInfo: ErrorInfo)
procedure RaiseVoucherLimit(FailureInfo: ErrorInfo)

Rules for Redeem (the tests only call it for a voucher that exists, is not yet redeemed, and with the setup record in place):

  1. A voucher is redeemable when "On Hold" is false and its Amount does not exceed "Max Voucher Amount" — an amount exactly at the limit still redeems; only strictly greater is a problem. Redeeming sets Redeemed to true and saves the voucher.
  2. Problems are checked in this order: the hold first, then the limit. Each problem raises an error built to the exact anatomy in the table below.
  3. Both errors must be collectible: when Redeem runs under an error-collecting caller, a raised problem must not stop the check sequence — a voucher that is on hold AND over the limit reports both problems, hold first, in that one run.
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
  • 14 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