Using The Enhanced Number Sequence Framework in Microsoft Dynamics AX 2012
Using The Enhanced Number Sequence Framework in Microsoft Dynamics AX 2012
Audience ..................................................................................................... 4
Overview..................................................................................................... 4
Supported scopes ................................................................................................................. 4
Overview
Microsoft Dynamics AX 2012 introduces two concepts to the number sequence framework:
segment and scope. A segment, which is synonymous with parameter, is a data entity such
as legal entity, operating unit, or fiscal calendar period that can be used to define a number
sequence. In the enhanced number sequence framework, a number sequence can have
more than one segment. A scope is a valid combination of segments used for a specific
transaction or master data entity. By using segment and scope, Microsoft Dynamics AX
2012 extends the capabilities of the number sequence framework.
All segments in a scope must be related to the underlying transaction or master data entity.
For example, a journal transaction will have a relationship with the segments of legal entity
and fiscal calendar period (through the transaction or posting date) that make up its scope.
The scope can be used to partition the entity instances or transactions based on the
segment values. In this example, a journal transaction might be partitioned into categories
based on the two segments in its scope.
A unique number sequence code must be created for every possible combination of legal
entity and fiscal calendar period instances. For example, if there are two legal entities with
IDs 10 and 20, and there are fiscal calendar periods for every calendar month in 2011, the
user must define separate number sequences for each combination. An example of a scope
instance is 20-Jan11. An example of a number sequence code for a journal might be JN-J-
20-Jan11, in which JN represents a journal. The number sequence format, J-20-Jan11, is
a string that is defined by the end user to represent the identifier for transactions for legal
entity 20 and fiscal calendar period January 2011. The actual instance of a journal might
have a generated number sequence such as J-20-Jan11-000340. (The last number in the
sequence, “000340”, is a system-generated number.)
The concept of a number sequence reference, which is synonymous with an extended data
type, has been carried forward from Microsoft Dynamics AX 2009. When you create a
number sequence, you must first create an extended data type (EDT) with a name —such
as SalesID—for the new number sequence. The label of this EDT is used as a reference. This
reference is used to define a field on a document or master data entity that requires a
number sequence.
Supported scopes
We are converting a subset of existing transactions and master data entities to allow them
to make use of scopes such as legal entity or shared scope. This enables Microsoft Dynamics
AX 2012 to ship with predefined scopes for this subset of entities. The rest of the data
entities will still have a default scope of Company (or DataArea).
Segment configuration
An administrator can configure the segments that are allowed for their requirements. For
example, out of the box, the application might allow two segments such as legal entity and
fiscal calendar period. However, only the legal entity segment might be included by default.
The administrator can enable both segments for their scenario by using the Segment
configuration form.
In Microsoft Dynamics AX 2012, most references use either Company (or DataArea) or legal
entity segments out of the box. There are several references for master data entities that
are shared across the application and do not use segments. However, the framework allows
an administrator to add segments such as fiscal calendar period. Figure 1 displays the
Segment configuration form, which can be accessed by using the navigation path
Organization Administration > Common > Number sequences > Segment
configuration.
All of the actions that were available in the Microsoft Dynamics AX 2009 forms are still
available in the action pane of the list page. In addition, the user can now run the Number
sequence wizard by clicking Generate in the New group of the action pane. The wizard
will create number sequences for all references that do not have number sequences defined
in the system.
In Microsoft Dynamics AX 2009, the wizard was run separately for each company to
generate the number sequences within each company. In Microsoft Dynamics AX 2012, the
new enhancements to the number sequence framework support segments other than
company. Therefore running the wizard is independent of the selected company in the
workspace.
10
A number of administrator tasks can be performed from the Details page. An administrator
can, for example, schedule an automated periodic cleanup for every number sequence by
entering intervals on the Automatic cleanup FastTab.
11
12
Extensibility scenarios
This section is primarily intended for ISV developers who want to call an API that extends
the NumSeqApplicationModule class to handle changes required by the enhanced number
sequence framework. This API is called to create new fields on documents or master data
entities that will use a number sequence. The customization scenarios by partners follow the
same pattern.
In a common extensibility scenario, a developer creates new fields and makes use of the
new number sequence framework to generate values for those fields. There are two main
extensibility scenarios:
Company scenario: Based on the default segment of Company (or DataArea).
Organization model and regulatory scenario: Based on the use of new segments
such as legal entity, operating unit, and fiscal calendar period.
The Microsoft Dynamics AX 2012 number sequence framework does not currently support
an extensibility scenario for adding arbitrary segments such as a warehouse or a site as a
segment in the definition of a number sequence for a reference. That kind of extensibility
would require significant customization to the number sequence framework.
In all extensibility scenarios, the assumption is that the developer is trying to set up a new
module, has already defined a field in a table, and is using the new number sequence
framework to generate values for that field.
A developer would typically follow these steps:
1. Make changes to support the new extended data type corresponding to the new field in
the table.
2. Call the API to generate the values by using the number sequence for that field.
An extensibility scenario in which the developer changes the scope of the reference from
DataArea to global (or shared) scope is also discussed.
13
Class declaration
/* Vehicle Number */
datatype.parmDatatypeId(extendedtypenum(VehicleNum));
datatype.parmReferenceHelp("Unique key for Fleet Management
vehicles");
datatype.parmWizardIsContinuous(false);
datatype.parmWizardIsManual(NoYes::No);
datatype.parmWizardIsChangeDownAllowed(NoYes::No);
datatype.parmWizardIsChangeUpAllowed(NoYes::No);
datatype.parmWizardHighest(999999);
datatype.addParameterType(NumberSeqParameterType::DataArea, true,
false);
this.create(datatype);
/* Trip Number */
datatype.parmDatatypeId(extendedtypenum(TripNum));
datatype.parmReferenceHelp("Unique key for trips");
datatype.parmWizardIsContinuous(false);
datatype.parmWizardIsManual(NoYes::No);
datatype.parmWizardIsChangeDownAllowed(NoYes::No);
14
datatype.addParameterType(NumberSeqParameterType::DataArea, true,
false);
this.create(datatype);
Use of the DataArea segment in Step 2 to describe the default segment for the extended
data types used for both vehicle number and trip number.
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.
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..
3. Create a Number sequences page in the parameters form of the new module.
See existing forms such as CustParameters or LedgerParameters for examples of
the implementation. Here is sample code for the numberSeqPreInit method on the
form.
void numberSeqPreInit()
{
numberSequenceModules = [NumberSeqModule::FleetManagement];
numberSeqApplicationModule = new NumberSeqModuleFleetManagement();
scope = NumberSeqScopeFactory::createDataAreaScope();
NumberSeqApplicationModule::createReferencesMulti(numberSequenceModul
es, scope);
tmpIdRef.setTmpData(NumberSequenceReference::configurationKeyTableMulti(n
umberSequenceModules));
}
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.
15
Void setVehicleNumber()
{
NumberSeq num
NumberSequenceReference numberSequenceReference;
numberSequenceReference =
FleetManagementParameters::numRefVehicleNumber();
if (numberSequenceReference)
{
num = NumberSeq::newGetNum(numberSequenceReference);
this.setField(fieldnum(FMVehicle, VehicleNumber),num.num());
}
}
16
1. 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.
2. 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. The following
example shows the code that returns the number sequence form handler for the
Vehicle form of the Fleet Management sample module.
NumberSeqFormHandler numberSeqFormHandler()
{
if (!numberSeqFormHandler)
{
numberSeqFormHandler = NumberSeqFormHandler::newForm(
FleetManagementParameters::numRefFMVehicleNumber().NumberSequenceId,
element,
FMVehicle_DS,
fieldnum(FMVehicle, VehicleNumber));
}
return numberSeqFormHandler;
}
3. 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 FMVehicle table to
support the number sequence for the VehicleNumber field.
17
1. In the class declaration of the data set 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.
2. Add the NumberSeqFormHandler method to the data set. The code in this method
will create an instance of the number sequence form handler and return it. The
following example shows the code that returns the number sequence form handler
for the data set of the Fleet Management sample module.
NumberSeqFormHandler numberSeqFormHandler()
{
if (!numberSeqFormHandler)
{
numberSeqFormHandler = NumberSeqFormHandler::newForm(
FleetManagementParameters::numRefFMVehicleNumber().NumberSequenceId,
element,
FMVehicle_DS,
fieldnum(FMVehicle, VehicleNumber));
}
return numberSeqFormHandler;
}
3. Add create, delete, and write methods to the data source for the data set 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 FMVehicle
table to support the number sequence for the VehicleNumber field.
18
/* Vehicle Number */
datatype.parmDatatypeId(extendedtypenum(VehicleNum));
datatype.parmReferenceHelp("Unique key for Fleet Management
vehicles");
datatype.parmWizardIsContinuous(false);
datatype.parmWizardIsManual(NoYes::No);
datatype.parmWizardIsChangeDownAllowed(NoYes::No);
datatype.parmWizardIsChangeUpAllowed(NoYes::No);
datatype.parmWizardHighest(999999);
datatype.addParameterType(NumberSeqParameterType::DataArea, true,
false);
this.create(datatype);
/* Trip Number */
datatype.parmDatatypeId(extendedtypenum(TripNum));
datatype.parmReferenceHelp("Unique key for trips");
datatype.parmWizardIsContinuous(false);
datatype.parmWizardIsManual(NoYes::No);
datatype.parmWizardIsChangeDownAllowed(NoYes::No);
datatype.parmWizardIsChangeUpAllowed(NoYes::No);
datatype.parmWizardHighest(999999);
19
3. Create a Number sequences page in the parameters form of the new module.
See existing forms such as CustParameters or LedgerParameters for examples of
the implementation. Here is sample code for the numberSeqPreInit method on the
form.
void numberSeqPreInit()
{
numberSequenceModules = [NumberSeqModule::FleetManagement];
numberSeqApplicationModule = new NumberSeqModuleFleetManagement();
scope = NumberSeqScopeFactory::createDataAreaScope();
NumberSeqApplicationModule::createReferencesMulti(numberSequenceModul
es, scope);
tmpIdRef.setTmpData(NumberSequenceReference::configurationKeyTableMulti(n
umberSequenceModules));
}
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.
4. Instantiate the scope for the two segments of Company (or DataArea), and fiscal
calendar period, and call the API with these two segments passed as parameters to the
number sequence framework. Use the following sample code:
Add a method on the parameter table (FleetManagementParameters) for the new
module.
NumberSeqScope scope =
NumberSeqScopeFactory::CreateDataAreaFiscalCalendarPeriodScope(curext()
,
FiscalCalendars::findPeriodByPeriodCodeDate
(CompanyInfo::fiscalCalendarRecId(),_date).RecId);
20
Void TripNumber()
{
NumberSeq num
NumberSequenceReference numberSequenceReference;
numberSequenceReference = FleetManagementParameters::numRefTripNumber();
If(numberSequenceReference)
{
num = NumberSeq::newGetNum(numberSequenceReference);
this.setField(fieldnum(FMTrip, TripNumber),num.num());
}
}
Notes
The Number sequences list page can be used to create number sequences for the
references with multiple segments described in the previous scenario.
The same approaches described in the Forms and Enterprise Portal examples in this
document are used for a number sequence field exposed on a form in the client or on
a page in Enterprise Portal.
Parameters forms have not been modified to support the assignment of number
sequences to references with multiple segments. The ISV or partner developer has
the option of modifying the Number sequences page in parameters forms to
provide this capability.
21
/* Vehicle Number */
datatype.parmDatatypeId(extendedtypenum(VehicleNum));
datatype.parmReferenceHelp("Unique key for Fleet Management
vehicles");
datatype.parmWizardIsContinuous(false);
datatype.parmWizardIsManual(NoYes::No);
datatype.parmWizardIsChangeDownAllowed(NoYes::No);
datatype.parmWizardIsChangeUpAllowed(NoYes::No);
datatype.parmWizardHighest(999999);
this.create(datatype);
/* Trip Number */
datatype.parmDatatypeId(extendedtypenum(TripNum));
datatype.parmReferenceHelp("Unique key for trips");
datatype.parmWizardIsContinuous(false);
datatype.parmWizardIsManual(NoYes::No);
datatype.parmWizardIsChangeDownAllowed(NoYes::No);
datatype.parmWizardIsChangeUpAllowed(NoYes::No);
datatype.parmWizardHighest(999999);
datatype.addParameterType(NumberSeqParameterType::DataArea, true,
false);
this.create(datatype);
22
NumberSeqScopeFactory::CreateGlobalScope();
return NumberSeqReference::findReference(extendedtypenum
(VehicleNumber));
}
Void setVehicleNumber()
{
NumberSeq num
NumberSequenceReference numberSequenceReference;
numberSequenceReference =
FleetManagementParameters::numRefVehicleNumber();
if(numberSequenceReference)
{
num = NumberSeq::newGetNum(numberSequenceReference);
this.setField(fieldnum(FMVehicle, VehicleNumber),num.num());
}
}
Note The same approaches described in the Forms and Enterprise Portal examples in
this document are used for a number sequence field exposed on a form in the rich client
or on a page in Enterprise Portal.
Code upgrade
Code upgrade scenarios are used when ISV developers need to upgrade the code for
existing number sequences. Code upgrades are performed when there has been a change in
the definition of a reference that allows for a different scope to make use of the new
capabilities of the framework. Another common scenario occurs when partners and
customer IT system developers need to upgrade the code for number sequences created
through customizations.
The following examples describe scenarios in which code changes are required:
The objects identified in an extensibility scenario, such as the enum
NumberSeqModule and the class NumberSeqModuleXXX, must be upgraded. Because
the name of the class has also changed, you need to change the name of the
23
The NumberSeq API that uses a segment of Company (or DataArea) to generate a number
sequence has not changed and there is no need to change any code that calls the API.
If your code pattern is to call the API using a number sequence code or ID, you will need to
make changes to correct the table relations. The use of RecId as the primary key has
caused changes to the NumberSequenceTable, which requires you to update the primary
key-foreign key relations on any application table you might have in your customization or
solution.
For example, the table relation NumberSequenceTable was the following on the
kanbanRule table:
kanbanRule.CardsNumberSequence == NumberSequenceTable.NumberSequenceCode
kanbanRule.DataAreaId == NumberSequenceTable.DataAreaId
kanbanRule.CardsNumberSequence == NumberSequenceTable.RecId
24
Data upgrade
If there are changes to the configuration of an extended data type, or reference, you will
need to modify the data upgrade scripts to reflect those changes. For example, suppose the
reference for a vehicle number had been based on the DataArea segment in Microsoft
Dynamics AX 2009 but has been changed to a global number sequence in Microsoft
Dynamics AX 2012. This means that the reference now has no segments.
If the format for a vehicle number is V_######, the same number, V_000001, might have
been generated in multiple companies when the segment was DataArea. If the reference
has been changed to a global number sequence, you will need to remove the duplicates in
the data before that data can be migrated to the target system during an upgrade. This is
accomplished by modifying the data upgrade script to handle the duplicates.
For information about how to modify data upgrade scripts, see the white paper “How to
write data upgrade scripts for Microsoft Dynamics AX” on the Microsoft Connect site.
25
This document supports a preliminary release of a software product that may be changed substantially prior to final
commercial release. This document is provided for informational purposes only and Microsoft makes no warranties,
either express or implied, in this document. Information in this document, including URL and other Internet Web
site references, is subject to change without notice. The entire risk of the use or the results from the use of this
document remains with the user. Unless otherwise noted, the companies, organizations, products, domain names,
e-mail addresses, logos, people, places, and events depicted in examples herein are fictitious. No association with
any real company, organization, product, domain name, e-mail address, logo, person, place, or event is intended
or should be inferred. Complying with all applicable copyright laws is the responsibility of the user. Without
limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a
retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or
otherwise), or for any purpose, without the express written permission of Microsoft Corporation.
Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights
covering subject matter in this document. Except as expressly provided in any written license agreement from
Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights,
or other intellectual property.
Microsoft, the Microsoft Dynamics Logo, and Microsoft Dynamics are trademarks of the Microsoft group of
companies.
26