Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Microsoft Dynamics AX 2012 Development Cookbook

You're reading from   Microsoft Dynamics AX 2012 Development Cookbook Customizing Dynamics AX to suit the specific needs of an organization is plain sailing when you use this cookbook of modifications. With more than 80 practical recipes it's the perfect handbook for all Dynamics AX developers.

Arrow left icon
Product type Paperback
Published in May 2012
Publisher Packt
ISBN-13 9781849684644
Length 372 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Mindaugas Pocius Mindaugas Pocius
Author Profile Icon Mindaugas Pocius
Mindaugas Pocius
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Microsoft Dynamics AX 2012 Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
1. Preface
1. Processing Data FREE CHAPTER 2. Working with Forms 3. Working with Data in Forms 4. Building Lookups 5. Processing Business Tasks 6. Integration with Microsoft Office 7. Using Services 8. Improving Development Efficiency 9. Improving Dynamics AX Performance

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

You have been reading a chapter from
Microsoft Dynamics AX 2012 Development Cookbook
Published in: May 2012
Publisher: Packt
ISBN-13: 9781849684644
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image