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

june

02jun2:00 pm2:30 pmBusiness Intelligence for Batch Manufacturers

16jun10:00 am10:30 amHow AP automation can speed up month-end close in D365 Finance

17jun11:00 am12:00 pmConfab Live with Stoneridge – Real Time Marketing Strategies for Success

23jun10:00 am10:30 amThe Modern Manufacturer: Cost Accounting in D365

30jun10:00 am10:30 amAP Automation Checklist for a 2022 Rebound

30jun2:00 pm2:30 pmAchieving Success: How Technology Is Helping Nonprofits Thrive

july

01jul11:00 am12:00 pmConfab Live with Stoneridge – Dataverse Virtual Entities

14jul12:00 pm12:30 pmBeyond Reporting - What Business Intelligence Can Do For Your Agribusiness

15jul11:00 am12:00 pmConfab Live with Stoneridge – Integration Strategies for End User Success

21jul10:00 am10:30 amThe Modern Manufacturer: Manufacturing Software in the Real World

21jul12:00 pm1:00 pmIs it Worth it to Upgrade to Dynamics 365 Finance and Supply Chain Management? - Everything AX Users Need to Consider

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