Microsoft Dynamics AX has a number sequence framework to generate alphanumeric number sequences that are used to identify transactions like Sales orders. This document describes the steps to create number sequences for new custom modules and also addresses a few issues that a developer may face during migrating number sequences from earlier AX versions to AX 2012.

Number Sequence Overview

Number sequences in Microsoft Dynamics AX are used to generate unique identifiers for master data records and for transaction records that require identifiers. Master data records and transaction records that require identifiers are referred to as a Reference.

Number sequences can be set up under Organization administration -> Common -> Number Sequence -> Number Sequence

Number Sequence Framework 1

1.     Scope – Scope defines which organization will use the number sequence. Scope can be Company, Shared, Legal entity or Operating entity.

2.    Segment – Number sequence format consists of segments. Number sequence with scope other than Shared will contain Segment that corresponds to the scope. In addition, it contains Constant and Alphanumeric segments. Constant segment will contain letters, numbers or symbols that does not change and Alphanumeric segment contains sets of numbers or letters that increment every time the number sequence is used.

Below example will create DAT-000001 number sequence.

Number Sequence Framework 2

3.  Continuous vs. Non-continuous number sequences – Continuous number sequence does not skip any numbers but numbers may not be used sequentially. Non-continuous numbers are used sequentially but they may skip a number. For example – If a particular transaction is cancelled, number sequence is generated but not used. In such case, continuous number sequence recycles this number later and can be used.

4.  Automatic cleanup of number sequence – In case of power failure or any other unexpected failure, system cannot recycle number sequence automatically. You can run the cleanup process manually.

Scenario

As a part of this document, a custom number sequence will be generated for custBudgetId EDT in custom module, Customer Budgets.

Steps

Here are the steps to create a new number sequence –

Creating a new Extended Data Type (EDT)

1.      Create a new Extended Data Type (EDT). Open AOT -> Data Dictionary -> Extended Data Types

2.      Right click on Extended Data Types and create a new EDT of type String, CustBudgetId

Number Sequence Framework 3

3.       Set the EDT properties

Modify Std. NumberSeqModule enumeration to add a new element

Create an enumerated value that represents new module, Customer Budgets by adding new element to NumberSeqModule base enumeration. Make sure to restart AOS after this modification.

Create a NumberSequenceModule class and a Parameter Table

1.      Create a new class named NumberSequenceModuleCustBudget. This class must extend NumberSeqApplicationModule.

  • Add NumberSeqModule() method as follows –

Number Sequence Framework 4

  • Add loadModule() method as follows. If you want to create multiple number sequences for different data types then specify characteristics for each data type.

Number Sequence Framework 5 for Dynamics AX 2012

2.      Create a Parameter table for new module, CustBudgetParameters.
Number Sequence Framework 6

  • This table should at least contain a Key field and find method. You can refer any existing Parameter table like CustParameters.

Number Sequence Framework 7

  • delete() and update() methods must be overridden and you can simply copy them from  existing Parameters table such as CustParameters.
  • Add numberSeqModule() method to return the element of new custom module, Customer Budget.

Number Sequence Framework 8

Load number sequence information for a module

In order to load this new number sequence information into Microsoft Dynamics AX, create a job as follows. This must be done only one time.

Number Sequence Framework 9

Generate number sequence

After number sequence information is loaded, use Setup number sequence wizard to generate number sequences.

1.      Go to Organization administration module -> Common -> Number sequences -> Number sequences

2.      Click Generate

3.      Complete the setup wizard.

Access new number sequence

In order to use CustBudgetId number sequence, create numRefCustBudgetId() static method. For each data types specified in loadModule() method, create static method in Params table as below.

Number Sequence Framework 10

Use new number sequence in an application

In order to get next number, use below code and make sure number sequence generation happens within transaction block.

Number Sequence Framework 11

Migrating Number Sequence from earlier AX version to AX 2012

Here are few tips to migrate number seuqences from earlier AX versions to AX 2012-

  1. TypeId function has been replaced by ExtendedTypeStr and EnumStr  in AX 2012.   ExtendedTypeStr(EDT _EDT) is used for Extended Data Type (EDT) with No Enum Type. EnumStr(Enum _Enum) is used for Extended Data Types with Enum Type.
  2. The code that generates next number sequence should be place within transaction block. (TTSBEGIN/TTSCOMMIT)
  3. Restart AOS after modifying NumberSeqModule Enumeration in order to see the change.

 

For more information about this topic or others, contact our Microsoft Dynamics AX experts at RSM or call us at 855-437-7201. You can also learn other valuable tips through our Dynamics Community Newsletter

Prepared By: Kshirsagar, Shamika