Number Sequence Framework in Dynamics AX 2012

maqk® by MolviDSLR Khan | 3:25 PM

Number sequence framework provides a mechanism to automatically generate alphanumeric sequence numbers on a configured field (EDT) with each new record in a table. This has very common yet significant usage in modern business applications.

I don't feel a practical example is required to understand the simple concept behind number sequences, yet I would provide one so that nothing at all remains ambiguous.

A picture worth a thousand words. Your employee number (illustrated above) is the best example to understand a sequence number and its use.

Now its clear, lets see how can we make such an auto generating and adjusting field in a table in Dynamics AX 2012.

AX provides controlled mechanisms, or frameworks to implement such features. The goal is to reduce code redundancy and rework, increase code re usability. A number sequence is such a common thing, you may require one for each entity in your system. And AX takes the responsibility that you should not be writing the same redundant code to implement number sequence in each table, hence the Number Sequence framework.

Configuring Number Sequence Framework

The main objective of this blog-post is to describe each practical step required in setting up the number sequence framework from scratch. Another post will be written to describe how to consume a configured number sequence.
Each object (new or existing one) required is mentioned with its primary usage along with its code. Simply create / modify these objects the way it is mentioned and you are done :)

Objects involved in Number sequence framework.

    1.) YourModuleEDT

    (new object)

    A new EDT is required where the new sequence number will be stored after being generated. This EDT will be consumed by the table the sequence numbers will be generated for, and the instance field will hold the generated sequence number. The consuming table and its details will be mentioned in the next post.

    2.) NumberSeqModule base enum

    (update existing system object)

    Base enums - NumberSeqModule: This holds each module for which a number sequence is to be generated. You are suppose to create a new item in this system base enum if you are configuring number sequence for a new module.

    AOS restart will be required after this change.

    3.) YourModuleClass

    (new object)

    A new class, name it NumSeqModule[yourclassmodulename] extending system class, 'NumberSeqApplicationModule'. The class details are as follows;
    /// configure all the datatypes in use by the module.
    protected void loadModule()
        NumberSeqDatatype datatype = NumberSeqDatatype::construct();
        /* Setup sequence numbers */
        //Your EDT Title
        datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);

    The second method, numberSeqModule() returns the base enum value of your module from the system base enum. A copy of this method would be required at the parameter table level as well.
    public NumberSeqModule numberSeqModule()
       return NumberSeqModule::Maqk;

    4. MymodueParams table

    (new object)

    The table has 2 main methods provided below;
    numberSeqModule - to return the base enum value of your module
    public NumberSeqModule numberSeqModule()
       return NumberSeqModule::YourModuleName;
    numRef - This method is will be called by the datasource of the consumer form (where the sequence number will be generated). It returns the reference of the EDT the sequence numbers will be generated upon.
    static client server NumberSequenceReference numRefYourEDTId()
        return NumberSeqReference::findReference(extendedtypenum(maqkEdt));

    5. MyModuleParam form

    (new object)

    The main purpose of this form is to display all generated sequence numbers for your module and provide mechanism to generate the number sequence modules (via some button e.g.). You need to drop the NumberSequenceReference table in the datasources section and override a few methods. The form code is provided below;

    public class FormRun extends ObjectRun
        container                   numberSequenceModules;//this will be used to pass module base enum value to other method of the forms
        boolean                     runExecuteDirect;
        TmpIdRef                    tmpIdRef;
        NumberSeqReference          numberSeqReference;
        NumberSeqScope              scope;
        NumberSeqApplicationModule  numberSeqApplicationModule;    
      public void init()
      void numberSeqPreInit()
          runExecuteDirect   = false;
          numberSequenceModules = [NumberSeqModule::Maqk]; //get your custom module base enum
          numberSeqApplicationModule = new NumSeqModuleMaqk();
          scope = NumberSeqScopeFactory::createDataAreaScope();
          NumberSeqApplicationModule::createReferencesMulti(numberSequenceModules, scope);
      void numberSeqPostInit()
          fieldnum(NumberSequenceReference, AllowSameAs)
      void executeQuery()
          if (runExecuteDirect)
              runExecuteDirect = true;
Thats all for the configuration. You can have several sequence numbers for different entities (consumer tables) for the same module. For each sequence number (for seperate entity), you will have to create a new EDT, a new consumer table (see next section), new consumer form, and a seperate numRef() method for each EDT in the param table (also mentioned there).

Using the configured Number Sequence

We will write a seperate post showing how to use all these configurations to see a number sequence in live action. So stay tuned!


Microsoft: http://msdn.microsoft.com/en-us/library/aa608474.aspx


Hire SharePoint Developers said...

Very nice and useful information shared, this blog is very good to acknowledge yourself and to remain updated, especially your writing style is very attractive, keep it up.

Post a Comment