Applying No. Series Design Pattern in Business Central OnInsert Trigger
DRAG DROP
You develop a table named Contoso Setup and a page.
You plan to use No. Series to automatically assign a unique number to data entries. You set up No. Series on the Vendor Nos. field of the Contoso Setup table.
You need to apply the No. Series Design Pattern to the trigger OnInsert().
Which four code segments should you use to develop the solution? To answer, move the appropriate code segments from the list of code segments to the answer area and arrange them in the correct order.

Community Insight
The core concept is the standard No. Series implementation flow: check if empty, get setup record, test field, init series, and assign value. The common trap is missing the 'begin' block or incorrect ordering of Get() and TestField().
This question tests the correct sequence for implementing the No. Series design pattern in an AL OnInsert trigger. It establishes that you must initialize the series only if the number is empty and ensure the setup table is retrieved before accessing fields.
Learners often place `ContosoSetup.Get()` before checking if the No. field is empty, or forget to wrap the logic in a `begin...end` block, leading to syntax errors or logical flaws where the series is initialized unnecessarily.
Community Discussion (2 comments)
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
Expert Analysis
Why the Answer Is Correct
The correct implementation of the No. Series design pattern in anOnInsert trigger follows a specific sequence to ensure data integrity. First, you check if the No. field is empty (If "No." = '' then begin). Second, you retrieve the setup record using Get (e.g., ContosoSetup.Get). Third, you verify the setup field is populated using TestField("Vendor Nos."). Fourth, you initialize the series using NoSeriesManagement.InitSeries. Finally, you assign the generated number to the current record's No. field. This sequence ensures the series is only initialized when necessary and uses the correct setup configuration.Why the Other Options Are Wrong
Incorrect options typically violate this logical flow. PlacingGet before the empty check might cause unnecessary database calls or errors if the setup isn't handled conditionally. Omitting the begin...end block after the if statement causes syntax errors because multiple statements follow the condition. Assigning the number before initializing the series results in an empty or invalid number being saved.Community Comment Notes
Community feedback highlights that the answer can be tricky due to the drag-and-drop format. One user noted that the sequence requires a 'begin' block after the if statement for the subsequent lines to make sense logically. Another comment emphasized that while the question doesn't explicitly demand strict sequencing in the UI, the code must follow the standard AL pattern: Check Empty -> Get Setup -> Test Field -> Init Series -> Assign Value.Exam Strategy
Memorize the standard boilerplate code for No. Series initialization in AL. Always start with the 'If No. = '' then begin' check, followed by getting the setup record, testing the field, initializing the series, and finally assigning the value.
Frequently Asked Questions
Why is ContosoSetup.Get() placed after the empty check?
It is placed there to optimize performance by only fetching the setup record when a new number is actually needed, avoiding unnecessary DB hits.
What happens if I omit TestField('Vendor Nos.')?
Omitting it risks runtime errors if the setup record exists but the specific No. Series field is blank, as InitSeries would fail or behave unpredictably.