Microsoft Dynamics AX Error: The Record Already Exists
I was recently working on an issue in Dynamics AX where, after a code move we started receiving the error: ‘Cannot create a record in “TableName.” The record already exists.’
One of the most common reasons for this error is, one of the unique index fields has duplicated value. I verified all the unique index requirements were satisfied and there were no duplicated index values.
After investigating, I found out that the RecId generated by the system was getting a value that has been previously used.
The RecId sequence for tables is stored in SystemSequences table and can get out of sync due to one/more of the following reasons:
1. Data is inserted in the SQL database directly
2. There has been tableId conflicts during model store move
To fix this error, we need to reset the NextVal field in SystemSequences table. NextVal field should be set to a value greater than the max RecId of the table.
Steps to resolve the error ‘record already exists’:
1. Get the tableId for the table.
a. You can find the tableId from AOT, under Properties for the table.
b. You can run a job to display the tableId in infolog.
2. Open SQL Server Management Studio and get the max value for RecId for the table, from SystemSequences table.
SELECT MAX(RecId) FROM <TableName>
3. Update the NextVal field to a value greater than the max RecId of the table.
SET NextVal = <Max RecId> + 1
WHERE TabId = <TableId>
4. Restart the AOS.