0023

Default Values on Insert

Basics
Easy
table-extension
oninsert
defaults

Default Values on Insert

Every new customer must enter your onboarding pipeline, stamped with the date it was registered and an initial review status. Records are created from pages, APIs, and background jobs alike — so the defaults must be applied by the table itself, at insert time, not by any page.

Requirements

  1. Create a table extension that extends the Customer table with two fields:
    • "First Registered On" of type Date
    • "Review Status" of type Code[10]
  2. Add an OnBeforeInsert trigger that stamps defaults:
    • a blank "First Registered On" (0D) becomes WorkDate()
    • a blank "Review Status" ('') becomes NEW
  3. Values the caller has already set must be kept — only blank fields get a default.

The defaults must hold even when a field is explicitly cleared just before insert, so the InitValue property can't solve this one — the decision has to be made at insert time.

What the tests check

The grading tests insert customers with Insert(true) and read them back from the database: blank fields must come back as WorkDate() / NEW, and pre-set values must come back unchanged. They also check the declaration of "Review Status": a Code field (values stored uppercase) with a maximum length of exactly 10.

Learn More

Hint 1
Table extensions can define table triggers like OnBeforeInsert — it runs before the row is written, so your changes land in the database.
Hint 2
Stamp a default only when the field is blank: 0D for an empty date, '' for an empty code.
Hint 3
Two small ifs inside OnBeforeInsert: assign WorkDate() only when the date is 0D, assign NEW only when the code is ''.
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.