Wire a Document to No. Series
Your workshop takes repair orders, and every order needs a unique document number — WO12-001, WO12-002, … — handed out by a number series the accountant can configure. Older code did this through the NoSeriesManagement codeunit; it is obsolete, and its replacement is the "No. Series" module from Business Foundation. You will wire a brand-new document table to it.
Requirements
- Create a table named
"Workshop Order"with:- a field
"No."of typeCode[20]— the primary key - a field
"No. Series"of typeCode[20]
- a field
- In the table's
OnInserttrigger, when"No."is blank (''):- assign the next number from the number series with code
WORKSHOP, and - stamp
"No. Series"withWORKSHOP, so every order records where its number came from.
- assign the next number from the number series with code
- A caller that has already set
"No."before insert keeps that number — and no number is drawn from the series, so the sequence stays gapless. - Add a public procedure on the table:
procedure PeekNextOrderNo(): Code[20]It returns the number the next automatically numbered order will get, without consuming it — peeking any number of times must not advance the series.
Use the "No. Series" codeunit from the Business Foundation module: GetNextNo draws a number, PeekNextNo only looks. Do not roll your own counter on top of the series tables — the module already handles incrementing and updating the series line for you.
What the tests check
The grading tests create the WORKSHOP series themselves with a randomly generated starting number, so hardcoded numbers cannot pass. They always insert with Insert(true) — table triggers do not run otherwise. They verify: the first order gets exactly the series' starting number (persisted under that key, not just in the variable); consecutive inserts number sequentially; "No. Series" is stamped on automatically numbered orders; PeekNextOrderNo returns the upcoming number; an insert right after peeking still gets that same number; a manually numbered order keeps its number; and a manual order does not consume anything from the series. They also check the declarations: both fields are Code (values stored uppercase) with a maximum length of exactly 20.
Learn More
Codeunit "No. Series" — GetNextNo draws the next number and advances the series, PeekNextNo only looks. The old NoSeriesManagement codeunit is obsolete.OnInsert, act only when "No." is blank: draw the number for series code WORKSHOP and stamp "No. Series" with the same code. A pre-set "No." must pass through with no series call at all.PeekNextOrderNo is a one-liner around PeekNextNo. If you reach for GetNextNo there instead, every peek consumes a number and the order inserted right after gets a later one — the tests catch exactly that.