Sunday, July 17, 2011

How to create ‘New Number Sequence’ if added new module in AX.

How to create ‘New Number Sequence’ if added new module in AX.
I have created a new Module “Payroll”
Setp1:
Need to create a new element in the baseenum “NumberSeqModule” as “Payroll” .The name should be baseenum should be the Module name.
Step2:
The field which need to be generated as number sequence it should be as extended data type.So create a extended data type and use this in the table.
Step3:
Create a new class as per module name as follows “NumberSeqRefernce_Payroll”
Add the following methods
Class NumberSeqRefernce_Payroll extends NumberSeqReference
{
}

public static client server NumberSeqModule numberSeqModule()
{
    return NumberSeqModule::Payroll;
}

protected void loadModule()
{
    NumberSequenceReference numRef;
    ;

    numRef.dataTypeId                     = typeId2ExtendedTypeId(typeid(EmpId));
    numRef.configurationKeyId       = configurationKeyNum(payroll);
    numRef.referenceHelp                = literalStr("Unique Key for Employee identification.The key is used when creating the Employee");
    numRef.wizardContinuous         = true;
    numRef.wizardManual                 = NoYes::No;
    numRef.wizardAllowChangeDown    = NoYes::No;
    numRef.wizardAllowChangeUp      = NoYes::No;
    numRef.wizardHighest            = 999999;
    numRef.sortField                = 1;

    this.create(numRef);
}


Step4:
To get the new module number sequence in the Basic > Setup > Number sequences > Number sequences, add the following code in the “NumberSeqReference” class methods

In Construct () method add the following line of code…
case (NumberSeqRefernce_Payroll::numberSeqModule()) : return new NumberSeqrefernce_Payroll(_module);

 In the moduleList() method….
moduleList += NumberSeqrefernce_Payroll::numberSeqModule();

Step5:
Go to Basic > Setup > Number sequences > Number sequences there click the Wizard button in the form & click the Next button.
 On the next screen, the number sequence for the Module “Payroll” will be shown,go further and finish the wizard.
After finishing the wizard select newly created number sequence in Number sequences form and go to General Tab and check the continuous check box

Step6:
Design the form and add the following code in the form
In Form
In Class declaration declare the
NumberSeqFormHandler numberSeqFormHandler;

Added the following method
NumberSeqFormHandler numberSeqFormHandler()
{
    if (!numberSeqFormHandler)
    {
        numberSeqFormHandler = NumberSeqFormHandler::newForm(EmployeeTable::numRefEmpId().NumberSequence,element, EmployeeTable_ds, fieldnum(EmployeeTable, EmpId));
    }
    return numberSeqFormHandler;
}

In the form DataSource Level added following methods

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

    super(_append);

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

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

No comments:

Post a Comment