The Number Series Pattern

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.

Note

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.

Technical description

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.

The Table reference field

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.

The Table reference field

Setup reference

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.

Note

The setup is most often done in Singleton tables, as described in Chapter 2, Architectural Patterns.

C/AL functions and variables

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:

  • The first implementation is in the 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.

  • Number Series allows us to block users from manually assigning values. Therefore, we need to test this when assigning values to the No. field. This code should be in the OnValidate of the No. field:
    IF "No." <> xRec."No." THEN BEGIN
      ExampleSetup.GET;
      NoSeriesMgt.TestManual(ExampleSetup."Example Person Nos.");
      "No. Series" := '';
    END;
  • Number Series also allows to link multiple series. From the UI, users can select any one of them. This is done using a function called 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;
  • This function is called from the OnAssistEdit trigger of the No. field in the page object:
    No. - OnAssistEdit()
    IF AssistEdit THEN
      CurrPage.UPDATE;

    Note

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

Implementations

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.

Note

The G/L Account master data does not use Number Series. All the countries have their own Chart of Accounts. Number Series don't add functional value here.

When issuing numbers for history records, such as Posted Sales Invoices or Issues Reminders, the Number Series are typically assigned in the original document.

Examples

These objects contain examples of the following Pattern:

Table ID

Description

18

Customer

36

Sales Header

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.4.181