Dynamics 365 Business Central: Quickly get next Sequence/Entry Number (without using FindLast -> Entry No. + 1)
The post explains how to retrieve the next sequence or entry number for ledger tables in Business Central using the Sequence No. Mgt. codeunit instead of the traditional FindLast() + 1 approach. This provides a cleaner, standard pattern for generating primary keys in ledger tables.

post Dynamics 365 Lab
"If the table primary key passed in is not Integer Data Type, a runtime error will occur."
Key points
- Business Central supports three methods for generating primary keys: No. Series, AutoSplitKey property, and finding the last number then adding 1
- Ledger tables use integer Entry No. fields that are automatically incremented, requiring sequence number generation when adding custom data
- Codeunit 9500 ‘Sequence No. Mgt.’ provides procedures GetNextSeqNo() and GetCurrentSeqNo() that simplify retrieving sequence numbers without manual FindLast() logic
- The sequence codeunit accepts only tables with integer primary keys; non-integer keys will cause runtime errors
- Using LockTable() before FindLast() may be necessary to prevent simultaneous insertion conflicts
Quotes
- “If the table primary key passed in is not Integer Data Type, a runtime error will occur.” (Critical constraint that developers must understand to avoid runtime failures when using the codeunit)
AL objects mentioned
As named in the post. A name that matches one object page by exact type and name links to it; the others stay as named.
- table 18 “Customer”
- table 37 “Sales Line”
- table 32 “Item Ledger Entry”
- table 17 “G/L Entry”
- table 5802 “Value Entry”
- table 21 “Cust. Ledger Entry”
- codeunit 9500 “Sequence No. Mgt.”
- codeunit “NoSeriesManagement”
Not found in BC28-30: codeunit “NoSeriesManagement”.
Possibly related
No source states these links: they share an object, a model read them, or a person found the same subject.
- BC 29 lets a single index span base table and table extension fields — possibly related: both name Table 32 “Item Ledger Entry”
- BC Friday Tips #56 Understand Missing Fields in Copy Documents — possibly related: both name Table 37 “Sales Line”
- BC Friday Tips #84 Why Is Your Item Missing from the Sales Line Lookup? — possibly related: both name Table 37 “Sales Line”
- Business Central 2026 release wave 2 (BC29): AL developers can turn indexes on/off in AL code — possibly related: both name Table 21 “Cust. Ledger Entry”
- Business Central 29.0: Major Change to Table Extensions & SQL. — possibly related: both name Table 32 “Item Ledger Entry”
- Business Central Development Serie - Part 2b: AI for BC Development — The Knowledge Gap That Ships to Production — possibly related: both name Table 37 “Sales Line”
- Business Central Queries: Simplifying Complex Data — possibly related: both name Table 21 “Cust. Ledger Entry”
- Creating Data Driven Text with AI in Business Central — possibly related: both name Table 21 “Cust. Ledger Entry”
- Deploy Analysis Views with AL Code in Business Central 2026 Wave 1 (No Manual Setup) — possibly related: both name Table 32 “Item Ledger Entry”
- Dynamics 365 Business Central – How to post a Sales Credit for an Item without affecting Inventory using an Item Charge — possibly related: both name Table 5802 “Value Entry”
Heads up
- warning: “If the table primary key passed in is not Integer Data Type, a runtime error will occur.” (about codeunit Sequence No. Mgt.)
Context
- Features: No. Series module, AutoSplitKey property, Sequence number management, Entry number generation, GetNextSeqNo procedure, GetCurrentSeqNo procedure
Source: Dynamics 365 Lab - Yun Zhu, community blog. Summary, key points and quotes are derived (CONTENT-NOTICE.md); read the original for the full text.