Technical6 min read

Create a custom number sequence in X++ (D365 F&O)

Custom number sequence in X++: EDT, reference in loadModule, accessor on the parameters table, setup in the application and NumberSeq call.

The short answer

A custom number sequence follows the number sequence framework: an extended data type (EDT) for the number; a "reference" declared in the loadModule method of a number sequence module class (NumberSeqDatatype + create); a static method returning that reference, usually on the module's parameters table; then, in code, NumberSeq::newGetNum(reference).num() to get the next number. In the application, the sequence is then created and linked to the reference (wizard or manual setup).

In D365 F&O you do not over-layer the standard module class: you add your reference through an extension (Chain of Command on loadModule) or create your own module class. Microsoft has opened standard modules' loadModule methods to extension (for example NumberSeqModuleProject in version 8.1.2).

Declaring the reference

The framework documentation (Dynamics AX 2012, still the reference for the pattern) shows the declaration in loadModule:

// In the module class's loadModule method (AX 2012 example)
NumberSeqDatatype datatype = NumberSeqDatatype::construct();

datatype.parmDatatypeId(extendedTypeNum(WorkOrderNum));
// ... other properties: label, scope, length, defaults
this.create(datatype);

In a D365 F&O extension, this code goes in an extension class of the module class, after the call to next loadModule(). Loading references is a one-time operation: once the module is loaded, the reference appears in the module parameters and in the number sequence wizard.

Setting up then consuming the sequence

  1. In the application, generate the sequence with the wizard (Organization administration > Number sequences > Number sequences > Generate) or create it manually, then link it to the reference and scope (shared, company…).
  2. Expose the reference through a static method on the parameters table, following the standard numRef… methods.
  3. In code (initValue, insert, service…), get the number:
// Get the next number from the reference
MyWorkOrderNum workOrderNum = NumberSeq::newGetNum(MyParameters::numRefWorkOrderNum()).num();

Common mistakes

  • Over-layering the standard module class instead of an extension.
  • Forgetting to reload references after deployment: the reference does not show in the parameters.
  • Not setting up the sequence in each company concerned (company scope): "number sequence not set up" error.
  • Taking the number too early (when the form opens) then abandoning the record: gaps in a continuous sequence.
  • Using a continuous sequence where it is not required: it is more expensive.

Having it generated

EDT, reference, accessor, initialisation: a custom sequence is a short ticket. Skalp AI writes the specification, generates the X++ code and unit tests, compiles with a best-practice check, then delivers a pull request to your Azure DevOps: nothing is merged without your technical architect's approval. See custom D365 F&O extensions, the bigger picture in building X++ without a consultant in 2026, and the Basic, Pro and Max plans (1 credit, ≈ €400 on Basic, €200 on Pro, consumed only when the code is generated).

Sources

Frequently asked questions

Where do you declare a new sequence reference in D365 F&O?

In a number sequence module class's loadModule method, through an extension class (Chain of Command) or a module class of your own.

How do you get the next number in X++?

NumberSeq::newGetNum(reference).num(), the reference being returned by a static method of the parameters table.

Why the "number sequence not set up" error?

The reference exists but no sequence is linked to it for the current scope or company. Use the wizard or link a sequence manually.

Ready to transform your D365?

Join the CIOs who develop their D365 tickets in 2–4 h for 1 credit (≈ €400 on Basic, €200 on Pro).