Creating a new number sequence in dynamics 365 ERP Finance and operations
The number sequences in Dynamics 365 for Finance and Operations are used to generate specifically formatted numbers for record identification. These number sequences can be anything from voucher numbers or transaction identification numbers to customer or vendor accounts. When developing custom functionality, often one of the tasks is to add a new number sequence to the system in order to support newly created tables. Adding a number sequence to the system is a two-step process.
First, we create the number sequence itself; second, we start using it in some particular form or from the code. D365 contains a list of NumberSeqApplicationModule derivative classes, which hold the number sequence's 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. The wizard is normally run as a part of the application initialization.
It can also be rerun any time later when expanding the D365 functionality used, where a setup of additional number sequences is required. The wizard also has to be rerun if new custom number sequences are added to the system.
Carry out the following steps in order to complete this recipe:
1. Create a new NumberSeqModuleCustomer_packt class in the D365 Project that extends the NumberSeqModuleCustomer class in the Application and add the following code snippet at the bottom of the loadModule_Extension() method
class NumberSeqModuleCustomer_packt extends NumberSeqModuleCustomer
{
public void loadModule_Extension()
{
NumberSeqDatatype datatype = NumberSeqDatatype::construct(); datatype.parmDatatypeId(extendedTypeNum(CustGroupId)); datatype.parmReferenceHelp("Customer group 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);
}
}
Step 02:
Create a new runnable class (Job) with the following lines of code, build the solution and run it:
class loadNumSeqCustPackt
{ ///
/// Runs the class with the specified arguments. ///
/// The specified arguments.
public static void Main(Args args)
{ //define the class variable
NumberSeqModuleCustomer_packt nymberSeqMod = new NumberSeqModuleCustomer_packt();
//load the number sequences nymberSeqMod.loadModule_Extension(); } }
Step 3
Run the number sequence wizard by clicking on the Generate button under Number sequence by going to Organization administration | Common | Number sequence and then click on the Next button
Step 4
Click on Details to view more information. Delete everything apart from the rows where Area is Accounts receivable and Reference is Customer group. Note the number sequence codes and click on the Next button
Step 5
On the last page, click on the Finish button to complete the setup
Step 6
The newly created number sequences now can be found in the Number sequence form
Step 7
Navigate to Organization administration | Number sequences | Segment configuration and notice the new Customer group reference under the Accounts receivable area
Step 8
Navigate to Accounts receivable | Setup | Accounts receivable parameters and select the Number sequencestab
Step 9:
The last thing to be done is to create a helper method for this number sequence. Create a new extension class CustParameters_Extension for the CustParameters table and add it to the Dynamics 365 Project and then create the following method and build the solution:
[ExtensionOf(tableStr(CustParameters))]
final class CustParameters_Extension
{ ///
/// Gets the number reference customer group id. ///
/// /// An instance of the NumberSequenceReference class.
client server static NumberSequenceReference numRefCustGroupId()
{ NumberSequenceReference NumberSeqReference;
NumberSeqReference = NumberSeqReference::findReference (extendedTypeNum(CustGroupId));
return NumberSeqReference; } }
Happy Learning,
Thank you!!