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…

4 Comments

  1. Marcel

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

  2. Brandon Carmichael

    Hello Marcel,

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

    Thank you,
    Brandon

  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.

    Thanks,
    Brandon

Submit a Comment

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

Upcoming Events

october

07oct12:00 pm1:00 pmThe Three Paths to Business Central from Dynamics GP

08oct11:00 am12:00 pmConfab with Stoneridge - Livestream - The Vision and Strategy of Microsoft Business Systems

14oct10:00 am10:30 amThe Modern Manufacturer - Managing Complex Cost Modeling

14oct12:00 pm12:30 pmGenerating Custom Inspection or Process Forms

19octAll Day22Stoneridge Connect Fall 2020

22oct11:00 am12:00 pmConfab with Stoneridge - Livestream - Stoneridge Connect Recap

28oct10:00 am10:30 amThe Modern Manufacturer - Engineering Change Management: Introduction of NEW Functionality for Manufacturers Using Dynamics 365

november

11nov10:00 am10:30 amThe Modern Manufacturer - Tears and Trauma of MRP

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!

X