Number sequence farmework overview in Dynamics AX 2012

For this demo, I will create New module along with NumberSequence, about creating Number Sequence without module you also use same steps just leave some steps base on Design picture above.ETDCreate...

For this demo, I will create New module along with NumberSequence, about creating Number Sequence without module you also use same steps just leave some steps base on Design picture above.

ETD

Create ETD ContosoId extends num datatype.

Table

Create Contoso Table with ContosoId field.

Enum

Create a new enum value Contoso in BaseEnum NumberSeqModule.

This value will be used to link number sequence to the module and to restrict displayed number sequence by module in Form.

NumberSeqModule Class

Create NumberSeqModuleXXX class

Create a new NumberSeqModuleXXX class, such as NumberSeqModuleContoso, which extends the NumberSeqApplicationModule class. The sample code for creating this class is as follows:

Use of the DataArea segment in Step 4 to describe the default segment for the extended data types used for ContosoId.

Note In Microsoft Dynamics AX 2009, number sequence references could be initialized by restarting the Application Object Server (AOS). In Microsoft Dynamics AX 2012, the initialization of references to populate the NumberSequenceDatatype and NumberSequenceParameterType tables has moved to the initialization checklist. To initialize the newly created references, run a job that executes the LoadModule method likes below.

You can also reinitialize all references by running a job that executes the LoadAll method in the NumberSequenceModuleSetup class. However, for reinitializing all references, you must ensure that there are no existing number sequences already defined in the system.

Then run the wizard in Organization Administration > CommonForms > Numbersequences > Numbersequences > Generate > run the wizard.

Parameters Table and Form

Create a Number sequences page in the parameters form of the new module.

You need to Create ContosoParameters Table along with form, See existing forms such as CustParameters or LedgerParameters for examples of the implementation.

These forms are using DetailsFormMaster form parten as Best Practice for Setup form.

Create ContosoParameters Table

• Add field key, Extends from ParametersKey

• Properties on Field key Visible = false, AllowEdit = false, AllowEditOnCreate = false

• Create index name Key with AllowDuplicate = No.

• Set table properties.

• TableContent = Default data

• ConfigurationKey

• CacheLookup = Found

• TableGroup = Parameter

• PrimaryKey = Key

• ClusterKey = Key

The sample code for creating method this table as below:

Create ContosoParameters form

Note This form can only be used for references that have a scope of DataArea. The administration forms described in the Setup and Administration of number sequences section can be used for references that have any scope. These forms can be found in Organization Administration > Common > Number Sequences

The data source of Parameters form likes picture below, you can also refer to CustParameters form for design.

Code example for form methods:

Code example for NumberSequenceReference data source methods

How to use on Table

Set number sequence in Contoso Table

Optional method – in case you don’t want to expose Number sequence on Form Level

From now on you can create new record in Contoso Table with number sequence.

How to use on Form

How to use on form level (In case you don’t want to expose NS in Table Level)

• In the class declaration of the form that will be accessing data, add a variable declaration for the number sequence handler. The following example shows the variable definition for a number sequence handler.
• Add the NumberSeqFormHandler method to the form. The code in this method will create an instance of the number sequence form handler and return it.
• Add create, delete, and write methods to the data source of the table that contains the field for which the number sequence is being used. The following code examples show these methods that are added to the data source for the Contoso table to support the number sequence for the ContosoId field.

Optional method

Continuous sequence

To avoid having gaps for continuous sequence you should add this code to the delete of the table.

Testing

Testing Number sequence by Job

Thank you for reading!