web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Update SystemSequence Table .

(0) ShareShare
ReportReport
Posted on by

Hi everyone,

   Error:   Cannot create a record in History of Allocated Numbers (CustomTableName). Customer account: 12345, 12345678. The record already exists.

when i insert the record into customtable the above error is showing because recid already exist which is same as the next value to be generated by system sequence table,so i updated the system sequence table nextvalue and gave full database sync but it still showing error . Please advice me if any other reason exist. 

here is my update query:

DECLARE @MaxRecID BIGINT
DECLARE @NextVal BIGINT

SELECT @MaxRecID = MAX(RECID)
FROM CustomTableName

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

IF (@NextVal > @MaxRecID)
BEGIN
PRINT 'CustomTableNamedid not need to be updated.'
END
ELSE
BEGIN
PRINT 'Updated CustomTableName 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 = 'CustomTableName'
AND SQLDICTIONARY.TABLEID = SYSTEMSEQUENCES.TABID
END

*This post is locked for comments

I have the same question (0)
  • Daniel Weichsel Profile Picture
    on at
    RE: Update SystemSequence Table .

    Hi Raghu,

    In SQL Server Management Studio, you can go to the table and then right click> Script table as> Create to> New query window.  You'll find a line in the generated script which defaults the RecId field from its sequence.  You could also drill down into the table constraints in the object explorer and script out just the RecId defaulting constraint (for example, DF__ASSETTABL__RECID__25FEC4E9).

    The sequence appears to match the table ID (e.g. if the AssetTable's ID is 832 in your environment, the RecId defaulting sequence is probably SEQ_832), but I wouldn't rely on that for anything important.

  • Community Member Profile Picture
    on at
    RE: Update SystemSequence Table .

    Hi Daniel, 

    Do you know how to find the sequence number that generates the RecID for a particular table?  For example, how did you know that SEQ_832 is the one that generates RecID for AssetTable ? 

    Thanks,

    Raghu. 

  • Verified answer
    Daniel Weichsel Profile Picture
    on at
    RE: Update SystemSequence Table .

    It is a feature of SQL Server, so check its documentation:

    docs.microsoft.com/.../sequence-numbers

  • Community Member Profile Picture
    on at
    RE: Update SystemSequence Table .

    Thanks Daniel, can you please give me more details about it?

  • Verified answer
    Daniel Weichsel Profile Picture
    on at
    RE: Update SystemSequence Table .

    Hi,

    Note that D365 uses SQL Server sequences for defaulting RecId values, for example:

    ALTER TABLE [dbo].[ASSETTABLE] ADD  DEFAULT (NEXT VALUE FOR [SEQ_832]) FOR [RECID]


  • Community Member Profile Picture
    on at
    RE: Update SystemSequence Table .

    thanks , but its not possible thing in my work because here involving lot of customized tables. so can you please tell me another option?

  • RaviRaj Profile Picture
    530 on at
    RE: Update SystemSequence Table .

    Hi hath,

    Try to remove the table and again create the new table  then sychronize.

  • Community Member Profile Picture
    on at
    RE: Update SystemSequence Table .

    Thanks for your reply, yeah i tried it already but no changes.

  • Suggested answer
    Mea_ Profile Picture
    60,284 on at
    RE: Update SystemSequence Table .

    Hi hath,

    Did you try to restart AOS after update? Because it could be cached by AX.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

#1
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

#1
Guy Terry Profile Picture

Guy Terry 2 Moderator

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans