When working with the ERP systems, issue numbers are issued to identify records in tables, which is a key requirement. Microsoft Dynamics NAV has a similar numbering engine built into the system as a part of the application. The engine is written in C/AL, and is accessible to be changed by developers.
More information can be found in the How Do I video, available at https://www.youtube.com/watch?v=1lG9rY_dmM4&list=PLhZ3P-LY7CqmVszuvtJLujFyHpsVN0U_w&index=8.
Although it is possible to change the behavior of the engine, best practice is not to do so. The engine can be used from any part of the system by implementing a few steps.
The NoSeriesManagement Codeunit has a number of functions, such as TestManual, InitSeries, and LookupSeries. We will focus on how to implement them as part of the primary key. Another example is to implement Number Series to automatically populate the Document No. field in the Journal Lines. This is outside the scope of this book.
To implement Number Series so as to uniquely assign values to the primary key, the following steps need to be implemented.
As a reference to the Number Series that was used, a field is required as part of the table. This field is called No. Series, and has a table relation with the No. Series table. This field is not a part of the user interface, and should be non-editable.
When a table needs to have more than one No. Series, a functional prefix should be added to explain what it is used for.
In order for the system to know which Number Series to use for which implementation, a reference should be implemented in a Setup table. Each implementation of the Number Series should have a minimum of one Setup Reference.
The setup is most often done in Singleton tables, as described in Chapter 2, Architectural Patterns.
In order for a Number Series implementation to behave as expected, we need to implement three C/AL Code snippets, and create a reference from the UI. The code is implemented in the Table using the Number Series. The following points are the features of Number Series:
OnInsert()
trigger of the table:IF "No." = '' THEN BEGIN ExampleSetup.GET; ExampleSetup.TESTFIELD("Example Person Nos."); NoSeriesMgt.InitSeries(ExampleSetup."Example Person Nos.", xRec."No. Series",0D,"No.","No. Series"); END;
In this example, the ExampleSetup
is a reference to the Setup table. NoSeriesMgt
represents Codeunit 396 NoSeriesManagement, and No. Series is a reference field to the Number Series that is used.
OnValidate
of the No. field:IF "No." <> xRec."No." THEN BEGIN ExampleSetup.GET; NoSeriesMgt.TestManual(ExampleSetup."Example Person Nos."); "No. Series" := ''; END;
AssistEdit
:AssistEdit() : Boolean ExampleSetup.GET; ExampleSetup.TESTFIELD("Example Product Nos."); IF NoSeriesMgt.SelectSeries(ExampleSetup."Example Product Nos.",xRec."No. Series","No. Series") THEN BEGIN NoSeriesMgt.SetSeries("No."); EXIT(TRUE); END;
OnAssistEdit
trigger of the No. field in the page object:No. - OnAssistEdit() IF AssistEdit THEN CurrPage.UPDATE;
An explanation of the functional use of the Number Series in Microsoft Dynamics NAV is available at http://dynamicsnavfinancials.com/2013/12/11/tip-33-number-series-nav-50-tips-series/.
Number Series is implemented in almost all the Master Data and Document tables in Microsoft Dynamics NAV using this pattern. An alternative implementation can be found using the Document No. assignment from the Journals.
When issuing numbers for history records, such as Posted Sales Invoices or Issues Reminders, the Number Series are typically assigned in the original document.
3.143.4.181