Previously, I wrote about creating number sequences as a part of a new module in Microsoft Dynamics 365 for Finance and Operations. In that series of posts, I created a subclass of NumberSeqModule which provided the logic to create number sequences in that module. This raises the question, “what if we need to add a number sequence to an existing module such as Accounts Receivable?”
In previous versions such as AX 2009 and AX 2012, the procedure to create a number sequence was the following.
- Create the data type.
- Add code in the loadModule method of the appropriate NumberSeqModule subclass.
- Add a method to the module’s parameters table that returns a reference to the number sequence.
Although the procedure is mostly the same, we must approach it differently in Dynamics 365. Unlike our NumberSeqModule subclass and parameters table, we cannot directly change the code (we can but we will have to rewrite it later). To accomplish this task, we need to use either events or the chain of command feature introduced in the platform 9 update. In my opinion, it makes the most sense to use chain of command.
Step 1: Create the data type
The data type for a number sequence is a string. There is nothing special about the data type and if we follow best practices, it will meet the requirements.
Step 2: Add code to the NumberSeqModule subclass
To create the number sequence, we need to extend the loadModule method of the appropriate NumberSeqModule subclass. For example, if we wish to add the number sequence to Accounts Receivable, we will use NumberSeqModuleCustomer. Using chain of command, we extend this class with a new class like the following.
[ExtensionOf(classStr(NumberSeqModuleCustomer))]
final class NumberSeqModuleCustomer_Extension
{
protected void loadModule()
{
next loadModule();
NumberSeqDatatype datatype = NumberSeqDatatype::construct();
datatype.parmDatatypeId(extendedTypeNum(ExampleId));
datatype.parmConfigurationKeyId(configurationKeyNum(ExampleConfigKey));
datatype.parmReferenceHelp(literalStr("@Example:ExampleIdHelp"));
datatype.parmWizardIsContinuous(false);
datatype.parmWizardIsManual(NoYes::No);
datatype.parmWizardFetchAheadQty(10);
datatype.parmWizardIsChangeDownAllowed(NoYes::No);
datatype.parmWizardIsChangeUpAllowed(NoYes::No);
datatype.parmWizardHighest(999999);
datatype.parmSortField(1000);
datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
this.create(datatype);
}
}
The key points to remember with this class is to end the name with “Extension” and use the ExtensionOf attribute. These are requirements for extending classes. Finally, in our loadModule method, there must be a next statement as it extends an existing method.
Step 3: Add a method to the parameters table
The last step is to add a method that returns a reference to the number sequence. The best practice is to put the method on the module’s parameters table. Like the NumberSeqModule class, we need to extend the table’s class. This code should look like the following.
[ExtensionOf(tableStr(CustParameters))]
final class CustParameters_Extension
{
public static NumberSequenceReference numRefExampleId()
{
return NumberSeqReference::findReference(extendedTypeNum(ExampleId));
}
}
Like the NumberSeqModule subclass, the name of the class needs to end with “Extension” and to use the ExtensionOf attribute (be careful to not use classStr instead of tableStr ). There does not need to be a next statement as this is a new method.
Final note
As with creating a new NumberSeqModule subclass, our number sequences will not appear in the parameter form until we execute the loadModule method. In this example, I used a runnable class.
class LoadNewDataTypes
{
public static void main(Args _args)
{
NumberSeqModuleCustomer module = new NumberSeqModuleCustomer();
module.load();
info('finished');
}
}