This topic describes how to implement the number sequence framework for a new module in Microsoft Dynamics AX. The topic will show how some number sequences could be implemented for the Fleet Management (FM) sample module. (Some of the following steps might be irrelevant if they have been previously performed for other purposes in your new Microsoft Dynamics AX module.)
The first step to implementing number sequences for a new module is to create a parameter table and a number sequence reference class.
- Create a parameter table for the new module: MyModuleParameters. For the Fleet Management module, this table is named FMParameters. The table must, at a minimum, contain a Key field and a find method. The delete and update methods must be overridden. These methods can be copied from one of the other parameter tables, such as BOMParameters.
- Create an enumerated value that represents all of the number sequences for the module by adding a new element to theNumberSeqModule base enum. For the Fleet Management module, the FM element was added to the base enum.
Note Configuration keys are used to detect the active number sequence references in your Microsoft Dynamics AX installation. If the configuration key is not enabled, the modules number sequence references are not displayed in the general References form. The user cannot see references from modules that are not enabled. - Create a new number sequence reference class named NumberSeqReference_MyModule. This class must extend theNumberSeqReference class. For the Fleet Management module, this class is named NumberSeqReference_FM.
- Add the numberSeqModule method to the new number sequence reference class. This method must return the element for your module from the NumberSeqModule base enum. The following code shows how this is done for the Fleet Management module.
public static client server NumberSeqModule numberSeqModule() { return NumberSeqModule::FM; }
- Implement the numberSeqModule and numberSeqReference methods for the parameters table.Copy these methods from one of the other parameter tables such as BOMParameters, and then change the names that are found in the method. Change the return value of the numberSeqModule method so that it references the number sequence class for your module.For example, the numberSeqModule method from the FMParameters table returnsNumberSeqReference_FM::numberSeqModule. The numberSeqModule method of the NumberSeqReference_FM class returns NumberSeqModule::FM (the FM element of NumberSeqModule).
- Add MyModuleParameters::find() as a new line in the selectParameters method of the Company class. The following example shows the line that was added for the Fleet Management module.
FMParameters::find();
- Create a form to display the new parameter table.It is important that the functionality of number sequence references is copied exactly from one of the other parameter forms (for example, CustParameters). Remember to change the names of the called methods.
- In the NumberSeqReference class, add a new line to the construct method—copy one of the existing lines, and then change the name of the class. The following example shows the line that was added for the Fleet Management module.
case(NumberSeqReference_FM::numberSeqModule()) : return new NumberSeqReference_FM(_module);
- In the NumberSeqReference class, add a new line to the moduleList method—copy one of the existing lines, and then change the name to reference your number sequence class. The following example shows the line that was added for the Fleet Management module.
moduleList += NumberSeqReference_FM::numberSeqModule();
The new number sequence framework is now established. The Number sequences tab should display the "No setup required" message.
Next, you will make number sequence references for the number sequences you are creating for your new module.
- In your number sequence reference class, override the loadModule method.
- In this new method, specify the characteristics of each number sequence reference you need in the new module. For example, the following code is from the loadModule method of the NumberSeqReference_FM class. It defines two number sequences used by the Fleet Management module.
protected void loadModule() { NumberSequenceReference numRef; ; // Setup VehicleNum ID numRef.DataTypeId = typeId2ExtendedTypeId(typeid(VehicleNum)); numRef.ReferenceHelp = "Unique key for Fleet Management vehicles"; numRef.WizardContinuous = false; numRef.WizardManual = NoYes::Yes; numRef.WizardAllowChangeDown = NoYes::No; numRef.WizardAllowChangeUp = NoYes::No; numRef.SortField = 1; this.create(numRef); // Setup TripNum ID numRef.DataTypeId = typeId2ExtendedTypeId(typeid(TripNum)); numRef.ReferenceHelp = "Unique key for trips"; numRef.WizardContinuous = false; numRef.WizardManual = NoYes::Yes; numRef.WizardAllowChangeDown = NoYes::No; numRef.WizardAllowChangeUp = NoYes::No; numRef.SortField = 2; this.create(numRef); }
Tip |
---|
For details about how to create a reference, see the comments written above the code for theNumberSeqReference.loadModule method.
|
After creating your references, the system automatically detects them when opening the parameter form. They should now be visible in the grid on the Number sequences tab.
For each reference specified in NumberSeqReferenceMyModule.loadModule, you must create a static method on your parameter table. Assuming that you have specified a reference for the MyDataType data type, create theMyModuleParameters::numRefMyDataType method.
- Copy a numRef method from one of the other parameter tables.
- Change the name of the method to numRefMyDataType.
- Add code that will return a number sequence reference object for that specific data type. For example, the following method retrieves the number sequence reference object that is used for the TripNum field.
server static NumberSequenceReference numRefTripNum() { return NumberSeqReference::findReference(typeId2ExtendedTypeId(typeid(TripNum))); }
To use the number sequence for a form in Microsoft Dynamics AX or in Enterprise Portal, you will typically add code to the data source for the form or data set. You can also retrieve a number sequence value directly in code. For example, the following example retrieves the next available vehicle number from the number sequence used for the VehicleNum field and displays it in the Infolog.
Info(NumberSeq::newGetNum(FMParameters::numRefVehicleNum()).num());
Forms
To use a number sequence for a form in Microsoft Dynamics AX, follow these steps.
- In the classDeclaration method of the form that will be accessing data, add a variable declaration for the number sequence handler. The following example shows the variable definition for a number sequence handler.
public class FormRun extends ObjectRun { NumberSeqFormHandler numberSeqFormHandler; }
- Add the NumberSeqFormHandler method to the form. The code in this method will create an instance of the number sequence form handler and return it. The following example shows the code that returns the number sequence form handler for the Trips form of the Fleet Management sample module.
NumberSeqFormHandler numberSeqFormHandler() { if (!numberSeqFormHandler) { numberSeqFormHandler = NumberSeqFormHandler::newForm( FMTrips::numRefFMTrips().NumberSequence, element, FMTrips_DS, fieldnum(FMTrips, TripNum)); } return numberSeqFormHandler; }
- Add create, delete, and write methods to the data source of the table that contains the field for which the number sequence is being used. The following code examples show these methods that are added to the data source for the FMTrips table to support the number sequence for the TripNum field.
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(); }
Enterprise Portal
To use a number sequence for a form in Enterprise Portal, follow these steps.
- In the classDeclaration method of the data set that will be accessing data, add a variable declaration for the number sequence handler. The following example shows the variable definition for a number sequence handler.
public class DatSetRun extends ObjectRun { NumberSeqFormHandler numberSeqFormHandler; }
- Add the NumberSeqFormHandler method to the data set. The code in this method will create an instance of the number sequence form handler and return it. The following example shows the code that returns the number sequence form handler for the FMTripAddEdit data set of the Fleet Management sample module.
NumberSeqFormHandler numberSeqFormHandler() { if (!numberSeqFormHandler) { numberSeqFormHandler = NumberSeqFormHandler::newForm( FMTrips::numRefFMTrips().NumberSequence, element, FMTrips_DS, fieldnum(FMTrips, TripNum)); } return numberSeqFormHandler; }
- Add create, delete, and write methods to the data source for the data set that contains the field for which the number sequence is being used. The following code examples show these methods that are added to the data source for the FMTrips table to support the number sequence for the TripNum field.
public void create(boolean _append = false) { element.numberSeqFormHandler().formMethodDataSourceCreatePre(); super(_append); element.numberSeqFormHandler().formMethodDataSourceCreate(); } public void delete() { element.numberSeqFormHandler().formMethodDataSourceDelete(); super(); } public void write() { element.numberSeqFormHandler().formMethodDataSourceWrite(); super(); }
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.