Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Update SystemSequence Table .

Posted on by Microsoft Employee

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

  • Daniel Weichsel Profile Picture
    Daniel Weichsel 1,657 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
    Community Member Microsoft Employee 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
    Daniel Weichsel 1,657 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
    Community Member Microsoft Employee on at
    RE: Update SystemSequence Table .

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

  • Verified answer
    Daniel Weichsel Profile Picture
    Daniel Weichsel 1,657 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
    Community Member Microsoft Employee 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
    RaviRaj 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
    Community Member Microsoft Employee on at
    RE: Update SystemSequence Table .

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

  • Suggested answer
    Mea_ Profile Picture
    Mea_ 60,278 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans