community postAL Developmentcommunity - not Microsoftreviewed - checked by Opus

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

Yun Zhu · 2025-08-20 · 479 words · about 2 min

"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.

Not found in BC28-30: codeunit “NoSeriesManagement”.

No source states these links: they share an object, a model read them, or a person found the same subject.

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.