Updating the Next Rec ID Sequence in Dynamics AX

By Nicole Gentz | June 26, 2017

Updating the next rec id sequence in dynamics ax

Recently I had to create database records outside of Dynamics AX. I used SQL to move some records from ISV tables to new standard tables within AX. There was a ton of data, so it was much faster to insert these records using SQL. Initially, I overlooked one important factor. When I created these records outside of the AX environment, the SystemSequences table was not updated.

The SystemSequences table stores the next RecID by table in the AX environment: https://msdn.microsoft.com/en-us/library/systemsequences.aspx
If this table is not updated properly, the users will see duplicate record errors that may not make sense to you. The users had sent me this error below. When I looked at the data, the Load ID did not exist. It didn’t throw an error about Rec IDs, so it’s a bit misleading.

RecIDSequence_Nicole

The issue was that I had created records in the WHSLoadTable outside of AX.  The SystemSequences table wasn’t updated, so the next value of the Rec ID was incorrect and throwing an error. In this situation, you must update the SystemSequences table. You’ll need to find the max value for the table and update to the max value + 1.

Here is a portion of the SQL used to fix this issue:

DECLARE @MaxRecID BIGINT
 	DECLARE @NextVal BIGINT

SELECT @MaxRecID = MAX(RECID)
FROM WHSLoadTable

SELECT @NextVal = NEXTVAL
	FROM SYSTEMSEQUENCES
	INNER JOIN SQLDICTIONARY
	ON SQLDICTIONARY.FIELDID = 0
	AND SQLDICTIONARY.name = 'WHSLoadTable'
	AND SQLDICTIONARY.TABLEID = SYSTEMSEQUENCES.TABID

	IF (@NextVal > @MaxRecID) 
	BEGIN
		PRINT 'WHSLoadTable did not need to be updated.'
	END
	ELSE 
	BEGIN
PRINT 'Updated WHSLoadTable from ' + CONVERT(VARCHAR(MAX), @NextVal) + '' to '' + CONVERT(VARCHAR(MAX), @MaxRecID + 1)
			
		UPDATE SYSTEMSEQUENCES
		SET NEXTVAL = @MaxRecID + 1
		FROM SYSTEMSEQUENCES
		INNER JOIN SQLDICTIONARY
		ON SQLDICTIONARY.FIELDID = 0
		AND SQLDICTIONARY.name = 'WHSLoadTable'
		AND SQLDICTIONARY.TABLEID = SYSTEMSEQUENCES.TABID
END

I hope this helps you out!

Related Posts

Recommended Reading:

5.27.22 Dynamics GP

How to Run Drop Ship Sales in Dynamics GP

Need to Invoice the Customer before you get the invoice from the vendor? This The freight forwarder has contacted you […]

Read the Article

New Features in Dynamics 365 Business Central 2022 Wave 1 Release – Protecting G/L Accounts From Being Deleted

There are a lot of exciting New Features in Dynamics 365 Business Central 2022 Wave 1 Release to get excited […]

Read the Article
5.25.22 Financials

Rounding Numbers in Power Automate

  If you’ve ever tried to round numbers in Power Automate, you have probably already run into the issue there […]

Read the Article

Manage U.S. Use Tax on Purchase Orders in Dynamics 365 Finance and Operations

  Managing sales tax requirements on your business purchase can be complicated, but Dynamics 365 Finance and Operations can help […]

Read the Article
5.19.22 Dynamics CRM

How to Write a Great Support Ticket in the Stoneridge Support Portal

Submitting a support ticket through the Stoneridge Support Portal is a quick and effective way to get assistance for any […]

Read the Article

Managing Your Business Through Uncertain Times Using Dynamics 365 Finance and Operations

  Dynamics 365 Finance and Operations (F&O) can help you make informed decisions on how to move your business forward. […]

Read the Article
5.13.22 Power Platform

Using Power BI Object Level Security

  The following article will demonstrate how to use Power BI Object Level Security to disable column data based on […]

Read the Article
5.12.22 Dynamics CRM

How to Use the Stoneridge Support Portal

Stoneridge Software’s support portal is an intuitive and useful function that makes it easy for you to access resources to […]

Read the Article
5.6.22 Dynamics GP

Dynamics GP Transaction Removal: Purchase Orders

  Are you having performance issues with Purchase Orders?  Do you find that there are old Purchase Orders on your […]

Read the Article

Start the Conversation

It’s our mission to help clients win. We’d love to talk to you about the right business solutions to help you achieve your goals.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!

X