Home > Sample chapters

Customizing Microsoft Dynamics AX 2009

  • 6/10/2009

Number Sequence Customization

In Chapter 6, the sample X++ code shows that a service order feature must have a number sequence to generate a unique identification number. To achieve this, you must customize the number sequence class, setting up the relationship between a module and a number sequence reference, and also associating the number sequence reference with the extended data type in which you want to store a number from the sequence.

When you want to create a new number sequence, you must first create an extended data type. The ID of the type is used as the identifier for the number sequence reference, so it must be unique. Figure 5-19 shows a string data type named BikeServiceOrderId.

Figure 5-19

Figure 5-19. BikeServiceOrderId extended data type

The properties on the extended data type are set to create a type with a maximum length of 20 characters, as shown in Table 5-15.

Table 5-15. BikeServiceOrderId Property Settings

Property

Settings

Type

String

Label

Service order

HelpText

Service order ID

StringSize

20

To implement a number sequence reference for service orders and assign it a specific service order number sequence, you must make changes to a NumberSeqReference class. To implement the reference in the Accounts Receivable module, among other references used by the sales order functionality, you add the following lines of X++ code to the loadModule method on the NumberSeqReference_SalesOrder class.

numRef.DataTypeId             = typeId2ExtendedTypeId(
                                typeid(BikeServiceOrderId));
numRef.ReferenceHelp          = "Unique key for the service order table, "+
                                "used when identification of a service "+
                                "order is allocated automatically.";
numRef.WizardContinuous       = false;
numRef.WizardManual           = NoYes::No;
numRef.WizardAllowChangeDown  = NoYes::No;
numRef.WizardAllowChangeUp    = NoYes::No;
numRef.SortField              = 100;
this.create(numRef);

These are the only modifications necessary to set up a new number sequence reference. The reference is available in the Accounts Receivable parameter form, and a number sequence can be created automatically by using the Number Sequence Wizard. You start the Number Sequence Wizard by clicking the Wizard button in the Number Sequences form located in the navigation pane under Basic\Setup\Number Sequences\Number Sequences.

The numRef table buffer in the preceding example is of a NumberSequenceReference table type. This table contains several fields that can be set depending on the reference you want to create. These fields are described in Table 5-16.

Table 5-16. NumberSequenceReference Field Explanations

Field

Explanation

DataTypeId

The ID for the reference. Use the ID of the extended data type.

ConfigurationKeyId

The configuration key that must be enabled for the reference to display. The configuration key should be set only if it is different from the key associated with the extended data type.

ReferenceLabel

The number sequence reference label should be set only if it is different from the label on the extended data type.

ReferenceHelp

The number sequence reference user interface Help field should be set only if the Help text is different from text in the HelpText property on the extended data type.

DataTypeSameAsId

Indicates that the reference can use the number from another number sequence. To make this possible, set the ID for the reference to the listed number sequence. This setting is usually applied to voucher references that use the ID of the journal as the voucher number.

GroupEnabled

Indicates that the reference is enabled for use with number sequence groups. This setting should be specified only if the reference can be set up for each number sequence group.

SortField

The position of the reference in the list. Use a sufficiently high number to avoid conflict with other or future references within the same module.

WizardLowest

The default value for the Smallest field when creating the number sequence with the Number Sequence Wizard.

WizardHighest

The default value for the Largest field when creating the number sequence with the Number Sequence Wizard.

WizardManual

The default value for the Manual field when creating the number sequence with the Number Sequence Wizard.

WizardContinuous

The default value for the Continuous field when creating the number sequence with the Number Sequence Wizard.

WizardAllowChangeDown

The default value for the To A Lower Number field when creating the number sequence with the Number Sequence Wizard.

WizardAllowChangeUp

The default value for the To A Higher Number field when creating the number sequence with the Number Sequence Wizard.

WizardFetchAheadQty

The default value for the Quantity Of Numbers pre allocation field when creating the number sequence with the Number Sequence Wizard. This field also enables the pre allocation number sequence feature, but it can’t be used in combination with a sequence marked Continuous.

Finally, the following method is implemented on the SalesParameters table. The method returns the new number sequence reference and should be used in the X++ code that requires numbers from the number sequence.

static client server NumberSequenceReference numRefBikeServiceOrderId()
{
    return NumberSeqReference::findReference(
                           typeId2ExtendedTypeId(typeid(BikeServiceOrderId)));
}