Wednesday, 11 December 2013

Number Sequence in Dynamics Ax

Microsoft Dynamics AX has a number sequence framework to generate alphanumeric number sequences that are used to identify transaction documents such as sales orders, purchase order and others.

We can create number sequence with existing module or new module. For both condition, first we create a table “BookTable” with two fields “BookId” and “Name” and create index on table called “BookIdx” and drag-drop “BookId” field on it. 

Figure 1. Create BookTable

Create a form “BookForm” and drag-drop “BookTable” in the datasource and create design according figure 2.

Figure 2. Create BookForm

Now, we create number sequence with existing module or new module.

 1. Create number sequence with existing module

1.Create a EDT that extends num and Add a relation in EDT.

Figure 3. Create EDT 


2.Edit a class NumberseqReference_CustTable  and  modify “loadModule()” method

   numRef.dataTypeId = typeId2ExtendedTypeId(typeid(Book_edt));        
    numRef.referenceHelp="Unique key for the Complaint Report";
    numRef.wizardContinuous = true;  
    numRef.wizardManual = NoYes::No;            
    numRef.wizardAllowChangeDown = NoYes::No;              
    numRef.wizardAllowChangeUp= NoYes::No;          
    numRef.wizardHighest= 999999;    
    numRef.sortField = 19;       
    this.create(numRef);

3.Modify CustParameters Table and Add methods.

   static client server NumberSequenceReference numRefComplaintId()
    {
     return NumberSeqReference::findReference(typeId2ExtendedTypeId(typeid(Book_edt)));
   }

4.In the “BookForm” classDeclaration declare NumberSeqFormHandler.

5.On “BookForm”  under “BookTable” datasource – Override write(), Delete(), create() methods like:

public void write()
{   super();
    element.numberSeqFormHandler().formMethodDataSourceWrite();
}
public void delete()
{   element.numberSeqFormHandler().formMethodDataSourceDelete();
    super();
}
public void create(boolean _append = false)
{   element.numberSeqFormHandler().formMethodDataSourceCreatePre();
    super(_append);
    element.numberSeqFormHandler().formMethodDataSourceCreate();
}

6.create method on “BookForm” form methods.

NumberSeqFormHandler numberSeqFormHandler()
{
    if (!numberSeqFormHandler)
        {
            numberSeqFormHandler = NumberSeqFormHandler::newForm(CustParameters::numRefComplaintId().NumberSequence, element, BookTable.dataSource(), fieldnum(BookTable, BookId));
        }
    return numberSeqFormHandler;
}

7. Goto>Basic>Setup>Number sequences>create new Number sequence code and set fields according to you
8. Goto> References>find new number sequence reference and set number sequence code field.


2. Create number sequence with new  module

1.Create a EDT that extends num and Add a relation in EDT
2.Modify numseqmodule Enum and a element “Book”.
3.Create  a class NumberseqReference_Book  that extend NumberSeqReference class and  Add loadModule() method and numberSeqModule().

protected void loadModule()
{
    NumberSequenceReference numRef;
    ;
    /* Setup Book Details */
    numRef.DataTypeId = typeId2ExtendedTypeId(typeid(Book_edt));
    numRef.ConfigurationKeyId = configurationkeynum(Test);
    numRef.ReferenceHelp ="Unique key for test identification. ";
    numRef.WizardManual = NoYes::No;
    numRef.WizardAllowChangeDown = NoYes::No;
    numRef.WizardAllowChangeUp = NoYes::No;
    numRef.SortField = 1;
    this.create(numRef);
}
public static client server NumberSeqModule numberSeqModule()
{
    ;
    return NumberSeqModule::Book;
}

4.Create  “BookParameters” Table and Add methods

client server static NumberSequenceReference numRefBookId()
{
    return NumberSeqReference::findReference(typeId2ExtendedTypeId(typeid(Book_edt)));
}
Figure 4. Create BookParameters Table

5.In the “BookForm” classDeclaration declare NumberSeqFormHandler.

6.On “BookForm”  under “BookTable” datasource – Override write(), Delete(), create() methods like:

public void write()
{   super();
    element.numberSeqFormHandler().formMethodDataSourceWrite();
}

public void delete()
{   element.numberSeqFormHandler().formMethodDataSourceDelete();
    super();
}

public void create(boolean _append = false)
{   element.numberSeqFormHandler().formMethodDataSourceCreatePre();
    super(_append);
    element.numberSeqFormHandler().formMethodDataSourceCreate();
}

7.create method on “BookForm” form methods.

NumberSeqFormHandler numberSeqFormHandler()
{
    if (!numberSeqFormHandler)
        {
            numberSeqFormHandler = NumberSeqFormHandler::newForm(BookParameters::numRefBookId().NumberSequence, element, BookTable.dataSource(), fieldnum(BookTable, BookId));
        }
    return numberSeqFormHandler;
}

8. Goto>Basic>Setup>Number sequences>create new Number sequence code and set fields according to you
9. Goto> References>find new number sequence reference and set number sequence code field.


3. In Dynamics Ax 2012 it is require that Create a new job with the following code and run it to call all loadModule:

           static void NumberSeqLoadAll(Args _args)
            {
                   NumberSeqApplicationModule::loadAll();
            }