Book Image

Microsoft Dynamics AX 2009 Development Cookbook

By : Mindaugas Pocius
Book Image

Microsoft Dynamics AX 2009 Development Cookbook

By: Mindaugas Pocius

Overview of this book

Microsoft Dynamics AX provides a comprehensive Enterprise Resource Planning (ERP) solution for mid-size and larger organizations. Dynamics AX implementations are used worldwide by thousands of customers. With the new version - Dynamics AX 2009 - the system is due to expand even more rapidly. Every new implementation requires some level of customization, and all organizations want this to be done to the highest standards using proven approaches. This step-by-step guide will help you manage your company's ERP information and operations efficiently, and solve your business process problems in an effective and quick way. This book focuses on commonly used custom modifications in major Dynamics AX modules. This book contains commonly used bits of code which were real-world tested in at least one successful Dynamics AX implementation. Many of the recipes were deployed in many implementations and even across several versions of Dynamics AX. The examples in this book cover various areas of Dynamics AX to help developers not only learn about programming, but also about the functional side of Dynamics AX. The book should help developers who already know the basics of Dynamics AX programming to step up to the next level. The recipes allow you to look at the development from the perspective of business processes. You will learn to enhance your user interface using various Dynamics AX UI elements. Managing your data and functions will become easier. You will also get numerous development tips and tricks from a Dynamics AX development expert.
Table of Contents (12 chapters)
Microsoft Dynamics AX 2009 Development Cookbook
Credits
About the Author
About the Reviewers
Preface
Index

Creating a new number sequence


Number sequences in Dynamics AX are used to generate a specifically formatted number for record identification. Numbers could be anything from voucher numbers or transaction identification numbers to customer or vendor accounts.

When developing custom functionality, very often one of the tasks is to add a new number sequence to the system to support newly created tables. Dynamics AX contains a list of NumberSeqReference derivative classes, which hold the number sequence 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 or newly created ones. The wizard is normally run as a part of the application initialization, but it can be rerun at any time later when expanding Dynamics AX functionality and new standard number sequences are required. The wizard also has to be rerun if new custom number sequences are added to the system.

In this recipe, we will add a new number sequence to the system. In a standard application, employee number is not driven by any number sequence, so we will enhance this by creating an employee number sequence functionality.

How to do it...

  1. Open the NumberSeqReference_General class in AOT, and add the following code to the bottom of loadModule():

    numRef.DataTypeId = typeId2ExtendedTypeId(typeid(EmplId));
     numRef.ReferenceHelp = literalstr("Employee identification");
     numRef.WizardContinuous        = false;
     numRef.WizardManual            = NoYes::No;
     numRef.WizardAllowChangeDown   = NoYes::Yes;
     numRef.WizardAllowChangeUp     = NoYes::Yes;
     numRef.WizardHighest           = 9999;
     numRef.SortField               = 7;
     this.create(numRef);
  2. Run the number sequence wizard by clicking on the Wizard button in Basic | Setup | Number sequences | Number sequences, and click Next:

  3. Delete everything apart from the line where Module is Basic and Reference is Employee (use keyboard shortcut ALT+F9 to delete lines). Note the number sequence code Basi_202, and click Next:

  4. On the last page, click Finish to complete the wizard:

  5. Find the newly created number sequence in Number sequences form:

  6. Open Basic | Setup | Company information and go to the Number sequences tab page. Here, we should see the new number sequence code along with the existing ones:

  7. The last thing to do is to create a helper method for this sequence. Locate CompanyInfo table in AOT and add the following method:

    public server static NumberSequenceReference numRefEmplId()
     {
         return NumberSeqReference::findReference(
             typeid2extendedtypeid(typeid(EmplId)));
     }

How it works...

We start the recipe by adding a number sequence initialization code into the NumberSeqReference_General class. As we can understand from its name, it holds initialization of all general number sequences that do not belong to any particular module. Employee number sequence partially matches this criterion, although we could have added the code to the NumberSeqReference_HRM class, which is used in the Human Resources module. Moreover, we could have created a totally new NumberSeqReference class. This is normally the case when new custom modules are built.

The code in loadModule() defines default number sequence settings to be used in the wizard like data type, description, highest possible number, etc. Additional options like starting sequence number, number format, and others could also be added here. All mentioned options could be changed while running the wizard. On the second step of the wizard, the Details >> button can be used to display more options. The options could also be changed later in the Number sequences form before or after the number sequence is actually used.

Once completed, the wizard creates a new record in the Number sequences form, which can then be used by the system.

The number sequences added to the NumberSeqReference classes are also automatically shown on relevant parameter forms. Sequences in the NumberSeqReference_General class are shown in the Company information form. For example, number sequences in the NumberSeqReference_HRM class are displayed in the Human Resource parameters form.

See also

Working with Data in Forms, Handling number sequences