How to Get No. Series in AL Business Central - Muhammad-Ali-Mughal/Microsoft-Dynamics-BC-AL-Extension GitHub Wiki

Introduction of No. Series

No. Series is a predefined behavior of Business Central which assigns Primary Keys to each record of a table. No. Series is highly beneficial because it creates a different Key at every new record. Each table has its own No. Series. No two tables share same No. Series directly.

Procedure of getting No. Series

First, you have to create a No. Series by searching for No. Series in the Search of Business Central. Then insert a new No. Series. Get its Code which you assign. For instance, in this case we take 'TEST' as No. Series. Now for using it in a page we can do in the following way:

trigger OnNewRecord()
    var
        NoSeries: Codeunit "NoSeriesManagement";
    begin
        if rec.Code = '' then
            rec.Code := NoSeries.GetNextNo('TEST', Today, true);
    end;

Here, this is defined in the page and OnNewRecord trigger will run when a new record in inserted into the table of the page. We are first creating a variable NoSeries and assigning it a Codeunit "NoSeriesManagement" (as I'm using an older version therefore I'm using NoSeriesManagement otherwise "No. Series" is the new Codeunit for No. Series.) The condition is that if currect record has Code field empty then it will assign it next No in the No. Series of 'TEST'.