Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Troubleshooting D365 FO RecId numbering in Production environement - Cannot create a record in Table (Table) the record already exists.

(0) ShareShare
ReportReport
Posted on by 17,134 Super User 2025 Season 1


In D365FO for each table the number RecId is a mandatory column added by the system for which it's a primary key. This field is linked with a sequence.

But same times RecId is not getting the correct sequence (does not increment).
In Sandbox environment we have access on the database from LCS but not for production environement.
 
To resolve this problem we must increment the minvalue in the sequence :
1- Get the table Id
select * from SQLDICTIONARY where NAME like 'custtable' and FIELDID = 0
2- Get max RecId from table
select max(RecId) from CUSTTABLE
3- Get next value from sequences 
select next value for dbo.SEQ_9136





 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

 

 

4- update the number value 
ALTER SEQUENCE SEQ_22096  MINVALUE 5637219000 RESTART WITH 5637219000
this solution is work fine in sandbox environement because we ave access on database.

Solution for  Production environement 

Here we must create a runable class to update the sequences values
 
class RecIdSequenceCustTable
{
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {
        CustTable custTable;
        Connection connection ;
        Statement statement ;
        RecId nextRecID;
        str sql ;
        int cnt ;
        
        connection = new Connection();
        statement = connection.createStatement();
        select firstonly custTable order by RecId desc;
        nextRecID = custTable.RecId + 1 ;
        connection.ttsbegin();
        sql = strfmt("ALTER SEQUENCE SEQ_%1 MINVALUE %2 RESTART WITH %2",custTable.TableId,nextRecID);

        cnt = statement.executeUpdate(sql);
        statement.close();

        connection.ttscommit();
    }
}
 
 
 
 
  • André Arnaud de Calavon Profile Picture
    292,888 Super User 2025 Season 1 on at
    RE: Troubleshooting D365 FO RecId numbering in Production environement - Cannot create a record in Table (Table) the record already exists.

    Hi Mohamed,

    Do you have a question or is your post intended as knowledge sharing? If you want to share your blog, please don't create a new question, but request a blog space on this forum: Request a New Blog or Blog to Syndicate - Microsoft Dynamics Community Support & Help

    Note that if there are issues with record ID generation, you can better first contact Microsoft Support. In a normal operating environment it should not give the error because of a duplicate Record ID.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,888 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,772 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans