Number sequences in Dynamics AX are used to generate specifically formatted numbers for record identification. for example Sales Id, Purchase Id, Journal number etc.
Very often we need to customize functionality which require new number sequence to be generated for new table designed.Dynamics AX contains a list of NumberSeqApplicationModule derivative classes, which holds the number sequence setup data for the specific module. These classes are read by the number sequence wizard, which detects existing number sequences and proposes to create the missing ones or newly added ones.
Suppose we have created new table “KitTable” with fields KitId and KitName, and we have to generate number sequence for KitId. This table belongs to Sales module.
Lets look at the steps to do this job :
1. Open the NumberSeqModuleCustomer class in the Application Object Tree (AOT), and add the following code to the bottom of the loadModule() method:
datatype.parmDatatypeId(extendedTypeNum(KitId));
datatype.parmReferenceHelp(“Kit ID”);
datatype.parmWizardIsContinuous(false);
datatype.parmWizardIsManual(NoYes::No);
datatype.parmWizardIsChangeDownAllowed(NoYes::Yes);
datatype.parmWizardIsChangeUpAllowed(NoYes::Yes);
datatype.parmWizardHighest(999);
datatype.parmSortField(20);
datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
this.create(datatype);
datatype.parmDatatypeId(extendedTypeNum(KitId));
datatype.parmReferenceHelp(“Kit ID”);
datatype.parmWizardIsContinuous(false);
datatype.parmWizardIsManual(NoYes::No);
datatype.parmWizardIsChangeDownAllowed(NoYes::Yes);
datatype.parmWizardIsChangeUpAllowed(NoYes::Yes);
datatype.parmWizardHighest(999);
datatype.parmSortField(20);
datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
this.create(datatype);
2. Create a new job with the following code and run it:
static void NumberSeqLoadAll(Args _args)
{
NumberSeqApplicationModule::loadAll();
}
static void NumberSeqLoadAll(Args _args)
{
NumberSeqApplicationModule::loadAll();
}
3. Run the number sequence wizard by clicking on the Generate button inOrganization administration | Common | Number sequences | Number sequences, and click on the Next button, as shown in the following screenshot:
4. Click on Details to view more information. Delete everything apart from the lines where Area is Accounts receivable and Reference is Kit Id. Note the number sequence codes, and click on the Next button.
5. On the last page, click on the Finish button to complete the set up.
6. The newly created number sequences can now be found in Organization administration | Number sequences | Number sequences
7. Open Organization administration | Number sequences | Segment configurationand notice the new Kit Id reference.
8. Open Accounts receivable | Setup | Accounts receivable parameters and go to the Number sequences tab page. Here we should see the new number sequence code.
9. The last thing to do is to create a helper method for this number sequence. Locate theCustParameters table in the AOT and create the following method:
public server static NumberSequenceReference numRefKitId()
{
return NumberSeqReference::findReference(extendedTypeNum(KitId));
}
public server static NumberSequenceReference numRefKitId()
{
return NumberSeqReference::findReference(extendedTypeNum(KitId));
}
Now lets see how the above code works :
We added a number sequence initialization code into the NumberSeqModuleCustomerclass. This class holds the initialization of all number sequences that belong to the Accounts receivable module. The code in the loadModule() method defines the default number sequence settings to be used in the wizard, such as data type, description, highest possible number, and so on.
Additional options, such as starting sequence number, number format, and others could also be added here. All mentioned options could be changed while running the wizard. The addParameterType() method is used to define number sequence scope. In the example we created a separate sequence for each Dynamics AX company.
Before we start the wizard, we need to initialize number sequence references. This is normally done as a part of the Dynamics AX initialization checklist, but in this example we have to execute it manually by calling the loadAll() method of theNumberSeqApplicationModule class.
Next, we will run the wizard. We will skip the welcome page and in the second step of the wizard, the Details button can be used to display more options. The options can also be changed later in the Number sequences form before or even after the number sequence is actually used. The last page shows an overview of what will be created. Once completed, the wizard creates new records in the Number sequences form for each company.
The newly created number sequence reference appears in the Segment configurationform. Here we can see that the Data area checkbox is checked, meaning that we will have separate number lists for each company. The number sequence setup can normally be located in the module parameter forms.
Next, we will run the wizard. We will skip the welcome page and in the second step of the wizard, the Details button can be used to display more options. The options can also be changed later in the Number sequences form before or even after the number sequence is actually used. The last page shows an overview of what will be created. Once completed, the wizard creates new records in the Number sequences form for each company.
The newly created number sequence reference appears in the Segment configurationform. Here we can see that the Data area checkbox is checked, meaning that we will have separate number lists for each company. The number sequence setup can normally be located in the module parameter forms.
No comments:
Post a Comment