Book Image

Microsoft Dynamics AX 2012 Development Cookbook

By : Mindaugas Pocius
Book Image

Microsoft Dynamics AX 2012 Development Cookbook

By: Mindaugas Pocius

Overview of this book

Microsoft Dynamics AX is a comprehensive Enterprise Resource Planning (ERP) solution for mid-size and large organizations. Dynamics AX implementations are used worldwide by thousands of customers. With the new version - Dynamics AX 2012 - 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. Written by one of the leading experts in Microsoft Dynamics AX, 'Microsoft Dynamics AX 2012 Development Cookbook' is packed with over 80 task-based and immediately reusable recipes that will help you manage your company's or customer'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. The recipes 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 practical recipes will also 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 and managing your data and functions will become easier.
Table of Contents (15 chapters)
Microsoft Dynamics AX 2012 Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface

Creating a new number sequence


Number sequences in Dynamics AX are used to generate specifically formatted numbers for record identification. It 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 NumberSeqApplicationModule derivative classes, which holds the number sequence 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 part of the application initialization. It can also be rerun at any time later when expanding the Dynamics AX 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.

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

How to do it...

Carry out the following steps in order to complete this recipe:

  1. 1. Open the NumberSeqModuleCustomer class in the Application Object Tree (AOT), and add the following code to the bottom of the loadModule() method:

    Note

    Downloading the example code

    You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

    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);
    
  2. 2. Create a new job with the following code and run it:

    static void NumberSeqLoadAll(Args _args)
    {
    NumberSeqApplicationModule::loadAll();
    }
    
  3. 3. Run the number sequence wizard by clicking on the Generate button in Organization administration | Common | Number sequences | Number sequences, and click on the Next button, as shown in the following screenshot:

  4. 4. Click on Details to view more information. Delete everything apart from the lines where Area is Accounts receivable and Reference is Customer group. Note the number sequence codes, and click on the Next button:

  5. 5. On the last page, click on the Finish button to complete the set up:

  6. 6. The newly created number sequences can now be found in Organization administration | Number sequences | Number sequences, as shown in the following screenshot:

  7. 7. Open Organization administration | Number sequences | Segment configuration and notice the new Customer group reference:

  8. 8. Open Accounts receivable | Setup | Accounts receivable parameters and go to the Number sequences tab page. Here we should see the new number sequence code:

  9. 9. The last thing to do is to create a helper method for this number sequence. Locate the CustParameters table in the AOT and create the following method:

    public server static NumberSequenceReference numRefCustGroupId()
    {
    return NumberSeqReference::findReference(
    extendedTypeNum(CustGroupId));
    }
    

How it works...

We start the recipe by adding a number sequence initialization code into the NumberSeqModuleCustomer class. As we can understand from its name, it holds the initialization of all number sequences that belong to the Accounts receivable module.

The code in the loadModule() method defines the default number sequence settings to be used in the wizard, such as data type, description, highest possible number, and so on. Additional options, such as starting sequence number, number format, and others could also be added here. All mentioned options could be changed while running the wizard. The addParameterType() method is used to define number sequence scope. In the example we created a separate sequence for each Dynamics AX company.

Before we start the wizard, we need to initialize number sequence references. This is normally done as a part of the Dynamics AX initialization checklist, but in this example we have to execute it manually by calling the loadAll() method of the NumberSeqApplicationModule class.

Next, we will run the wizard. We will skip the welcome page and in the second step of the wizard, the Details button can be used to display more options. The options can also be changed later in the Number sequences form before or even after the number sequence is actually used. The last page shows an overview of what will be created. Once completed, the wizard creates new records in the Number sequences form for each company.

The newly created number sequence reference appears in the Segment configuration form. Here we can see that the Data area checkbox is checked, meaning that we will have separate number lists for each company. The number sequence setup can normally be located in the module parameter forms.

See also

See Chapter 3, Working with Data in Forms:

  • Using a number sequence handler