Initializing Number Sequences from Code in AX

by | Updated August 15, 2016 | Development, Dynamics AX

While writing unit tests for a feature I was developing in AX I decided to use the SysTestSuiteCompIsolateClassWithTts test suite class. This class isolates the changes made by your test by creating a new, temporary company, running everything within a transaction, and aborting the transaction when the suite finishes. Unfortunately it does not setup any number sequences for you; and because a new company is created every time the tests are run, you cannot run the Number Sequence wizard like you would normally do. To fix this you must initialize the number sequences yourself from within your test’s transaction.

Initializing a Number Sequence

Number Sequences are initialized for a specific EDT and scope.  This method initializes the number sequences for the InventDimId, SalesId, and ItemId extended data types.  Data for each of these types is added to the temporary TmpNumberSeqCreate table by a helper method before being processed by the NumberSequenceTable::createFromTmpNumberSeqCreate method.


The setupNumberSequence helper method is responsible for initializing the temp table with information about the extended data type.

Alternatively, you could setup all number sequences by populating the temp table with the TmpNumberSeqCreate::buildWizardList method. This is usually overkill for targeted unit tests because the time spent initializing the number sequences is usually greater than the time spent executing the tests.  This code can be called from the setUpTestCase method of your test suite.

Related Posts

  • Over on the AX Support site on MSDN, Daniel Durrer has taken the time to keep tabs on the latest builds for Microsoft Dynamics AX 4.0, 2009 and 2012.  I…

  • If you are using TFS as your Dynamics AX code repository, there are a few things you will want to do to make life easier for those around you. Dynamics…

  • I recently came across an issue in Dynamics AX when creating a new payroll tax transition from the Tax transaction history detail inquiry. The Dynamics AX error stated: Field Tax…


  1. Marcel

    Thanks, this is very useful.
    I wish more people cared about unit tests.

  2. Brandon Carmichael

    Hello Marcel,

    We couldn’t agree more. Unit tests are an important step in development.

    Thank you,

  3. Eduardo Rotundo Soto

    Hi Mr. Mark Nelson

    This is a nice post to do the process to start the number secuence. Thanks for this!

    In other way i want to ask to you if it’s possible.

    What i need to register a number secuence into NUMBERSEQUENCEDATATYPE table? Because when i try to do a createReferenceMulti from NumberSeqApplicationModule i got a error like “the value XX it’s not located into a map” and the problem it’s this module don’t exist in this table

    Best regards

  4. Brandon Carmichael

    Hello Eduardo,

    After talking with Mark, we suggest that you take a look at the NumberSequenceTable table’s autoCreate method.


Submit a Comment

Your email address will not be published. Required fields are marked *

Upcoming Events


14jan11:00 am12:00 pmConfab with Stoneridge - Livestream - Looking Forward: Predictions for Technology in 2021

20jan10:00 am10:30 amThe Modern Manufacturer - Demand Forecasting Functionality

27jan12:00 pm12:45 pmFour Keys to Choosing the Best ERP or CRM Solution: Part 1 – Fit

28jan11:00 am12:00 pmConfab with Stoneridge - Livestream - Ask the Experts!


03feb10:00 am10:30 amThe Modern Manufacturer - Enterprise Asset Management

03feb12:00 pm12:45 pmFour Keys to Choosing the Best ERP or CRM Solution: Part 2 – Platform

10feb12:00 pm12:45 pmFour Keys to Choosing the Best ERP or CRM Solution: Part 3 – Implementation Partner

11feb11:00 am12:00 pmConfab with Stoneridge - Livestream - Live Agents, Power Virtual Agents, Omnichannel – Oh My!

16feb12:00 pm12:45 pmFour Keys to Choosing the Best ERP or CRM Solution: Part 4 – Cost

17feb10:00 am10:30 amThe Modern Manufacturer - Machine Maintenance Work Orders

25feb11:00 am12:00 pmConfab with Stoneridge - Livestream - Surfing Through the Dynamics 365 Wave 1 2021 Release

About Stoneridge
Stoneridge Software is a unique Microsoft Gold Partner, with emphasis on partner. With specialties in Microsoft Dynamics 365, Microsoft Dynamics AX, Microsoft Dynamics NAV, Microsoft Dynamics GP and Microsoft Dynamics CRM, we focus on attracting the most knowledgeable experts in the field to our team, and prioritize delivering stellar solutions with maximum impact for your business. At Stoneridge, we are deeply committed to your results. Each engagement is met with a dedicated team, ready to provide thorough, tailored, and expert service. Based in Minnesota, we intentionally “step into your shoes,” wherever you are. We focus on what you care about, and develop trusting, long-term relationships with our clients.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!