D365F&O, Developer, Uncategorized

How to create a new number sequence in D365 F&O – Using X++

The main purpose of creating a new number sequence is to be used as a unique identifier, readable alphanumeric number for Master data or can be used as a business Id for transaction details records.

In general, there is not any big difference between creating a new number sequence in D365FO and AX2012.

To create a new number sequence you must follow those steps:

Step 1) In my case, I have to create a new number sequence for the WHS module so I must extend WhsNumberSeqModuleWHS class. If you want to create a number sequence for another module you should extend another class (Ex NumberSeqModule_ModuleName) or if you want to create a number sequence for a new module first you should add the new module at NumberSeqModule base enum.

Step 2) Create a new EDT which will represent the value of your new number sequence Id. My new EDT is RouteId.

Step 3) Extend Number Sequence class for WHS module to add our custom logic for creating new number sequence Id.

  • Add our new number sequence based on RouteId EDT and other default parameters
  • Add our module class to numberSeqModuleNameMap map
/// <summary>/;
///  Extend NumSeq class for WHS module to add our new number seq
/// </summary>
public final class WhsNumberSeqModuleWHS_Extension 
    /// <summary>/;
    ///  Add our new number sequence based on MSWHSRouteId EDT and other parameters 
    /// </summary>
    public void loadModule_Extension()
        NumberSeqDatatype  dataType = NumberSeqDatatype::construct();

        datatype.parmReferenceHelp("Route ID");
        datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);

    /// <summary>
    /// Add our module to map
    /// </summary>
    /// <param name = "_numberSeqModuleNameMap">Map</param>
    [SubscribesTo(classStr(NumberSeqGlobal), delegateStr(NumberSeqGlobal,buildModulesMapDelegate))]
    static void buildModulesMapSubscriber(Map _numberSeqModuleNameMap)
        NumberSeqGlobal::addModuleToMap(classNum(WhsNumberSeqModuleWHS), _numberSeqModuleNameMap);

    /// <summary>
    /// return Number Sequence Reference from EDT 
    /// </summary>
    /// <returns>numberSequenceReference</returns>
    static numberSequenceReference numRefMSWHSRouteId()
        return NumberSeqReference::findReference(extendedTypeNum(RouteId));

    /// <summary>
    /// Return our module - WHS
    /// </summary>
    /// <returns>NumberSeqModule</returns>
    public NumberSeqModule numberSeqModule()
        next numberSeqModule();
        return NumberSeqModule::WHS;


Step 4) Create a new batch job (Runnable class) and run it to load our new number sequence Id

/// <summary>/;
/// Run the new number sequence that we have created
/// </summary>
class NumberSeqJob
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">specified argument</param>
    public static void main(Args _args)
        WhsNumberSeqModuleWHS numberSeqMod = new WhsNumberSeqModuleWHS();


Step 5) After the job is executed, run Number Sequence Wizard.

Path: Organization administration > Number Sequence

And the click generates, will open a new form to start the number sequence generation process. your new number Sequence is well added.

And then you can find your number sequence Id

Step 7 ) Test your number sequence, run the following job

static void number(Args _args)
NumberSeq  numberSeq;
MyNumSeqEDT num;
numberSeq = NumberSeq::newGetNum(WhsNumberSeqModuleWHS::numRefID());
num = numberSeq.num();

Extending Microsoft Dynamics 365 Finance and Supply Chain Management Cookbook
Microsoft Dynamics 365: Finance and Operations Apps Developer – ( MB-500 )
Implementing Microsoft Dynamics 365 for Finance and Operations Apps – Second Edition

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s