0004

Block Negative Credit Limits

Basics
Easy
table-extension
onvalidate
validation

Block Negative Credit Limits

Your company tracks an internal credit ceiling on each customer, and data-entry typos keep producing negative amounts. You'll add the field — and make it defend itself.

Requirements

  1. Create a table extension that extends the Customer table.
  2. Add a field named "Internal Credit Limit" of type Decimal.
  3. Give the field an OnValidate trigger that raises an error when the value is negative. The error message must contain the exact text must not be negative.
  4. Zero and positive values are accepted.

What the tests check

The grading tests validate a positive value and read it back, validate zero, and check with asserterror that validating a negative value fails with a message containing must not be negative — both for a large negative amount and for the boundary value -0.01.

Learn More

Hint 1
Validation logic for a single field lives in that field's OnValidate trigger, inside the field declaration.
Hint 2
Inside the trigger, compare the field to 0 and raise Error(...) when it is negative.
Hint 3
The tests check that the message contains exactly must not be negative — for example Error('Internal Credit Limit must not be negative.').
ALBusiness Central 28.5
Press Compile to check your code compiles — Submit runs the tests.
The code editor is desktop-only
Open this problem on a computer to write and run code. Reading the description, tests and discussion works fine here.