Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

AX 2012 RecId problem

Posted on by 1,226

Hi,

This question is specially for the persons who have worked to build the AX kernel or have access to it's code.

My AX version: AX 2012 R2 CU7 (both app and kernel)

I had few custom tables which were in ISV layer before and later, for some reason, were moved to VAR layer. The procedure adopted was

1. Create a separate new database and create the replica of custom tables in this database.

2. Copy all data of custom tables from AX business DB to this new database. 

3. Delete the model (with elements in ISV layer). Compile, synch, CIL etc. This deleted the custom tables in AX business DB.

4. Import the model in VAR layer (this model have same elements but in VAR layer). Compile, synch, CIL etc. All the tables are again created in AX business DB.

5. Stop AOS. Get the data back into custom tables from new database to AX business DB.

6. Run a SQL script to update the 'SYSTEMSEQUENCES' table for each custom table record with following logic

'NextVal' field value = (Existing largest recid for the table) + 1.

7. Start the AOS.

During normal operation, the custom tables' randomly gives the error - 'Record already exist' even when no unique index is violated by data. Looking back at the specific table's record in 'SYSTEMSEQUENCES' table in SQL, the value of 'NextVal' field has gone back to one of the existing recid.

Now this is a mystery to me how system is actually assigning recids to new records in table. All I know is a stored procedure which increments the recid to provide next recid. But I guess there is some more logic in kernel which caches the recid and manipulates the value in 'NextVal' field of 'SYSTEMSEQUENCES' table record.

AX Kernel Experts - Please help me out. What should be done to fix the issue?

I have also tried executing the methods of 'SystemSeuqence' class for all the custom tables to make recids in order but no luck.

Any help will be appreciated.

Regards,

Deepak

*This post is locked for comments

  • Verified answer
    DG Profile Picture
    DG 1,226 on at
    RE: AX 2012 RecId problem

    Hi,

    Andre -Thanks for reply.

    I finally found the problem. It is complicated. But will try to explain here, it may help someone later.

    Initially 'SYSTEMSEQUENCES' table had record for each of the custom table. Then I deleted the table & re-created them & populated data back into them via SQL. (This is till step 5 as I have described initially) This process ended up in records for 'SYSTEMSQUENCES' for custom tables randomized.

    Few custom tables' records were have wrong 'NextVal' value while few other custom tables' do not have any record at all (Only Kernel coder know why?). When in step 6, I ran a SQL script to correct the 'NextVal', it only corrected the 'NextVal' of custom tables for which 'SYSTEMSEUQUENCES' records were present.

    When normal operation begun and a record needs to be inserted in a custom table for which 'SYSTEMSEQUES' record was missing, 'sp_getNextRecId' stored procedure must have been run and it created a new record with default RecId. As the default record ID record was already present in the table, it started to give me error.

    Solution - I ran the step6 script again to sort this out.

    Regards,

    Deepak

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,280 Super User 2024 Season 2 on at
    RE: AX 2012 RecId problem

    Hi Deepak,

    Lately when I wrote the blog about the continuous number sequence the database where it occured was missing almost all stored procedures. I mentioned that the blog was about number sequences but in the environment where it happened also the sp_ getnextrecid was missing. It was strange to see that in this case record ids were created for each table. So I think there should be some more logic in the kernel we are not able to see.

    I cannot help much as I'm having a vacation now without access to some machines.

    Please check if the aos user really has execute permssions on the sp.

    Did you also test to setup a new environment from scratch to see if this will work correctly?

  • DG Profile Picture
    DG 1,226 on at
    RE: AX 2012 RecId problem

    Hi Ibrahim,

    Thanks for your answer.

    The AOS is restarted many times but no impact.

    The table id changes are taken care of. The SQL script in step 5 (to bring data back) is based on name of the table not AX Id.

    Regards,

    Deepak

  • Ibrahim Salah Mohamed Profile Picture
    Ibrahim Salah Mohamed 1,165 on at
    RE: AX 2012 RecId problem

    i think you will need to restart the AOS after changing values on table SYSTEMSEQUENCES

    also take into consideration changing table ID after moving objects between layers

  • DG Profile Picture
    DG 1,226 on at
    RE: AX 2012 RecId problem

    Hi André,

    Thanks for your reply.

    My problem is related to table recid while your blog is about number sequence. The recid related stored procedure is 'sp_GetNextRecId' which is present in the AX business DB. If this stored proc. would have been missing, creating record in any table would not be possible. But I am getting issue only with my custom tables and that too in random sequence. Also I can replicate the issue in multiple environments.

    Do you have the information what is the logic which AX kernel applies to get next recid for a table record? Or some other way by which messed up rec id can be sorted.

    Regards,

    Deepak

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,280 Super User 2024 Season 2 on at
    RE: AX 2012 RecId problem

    Hi,

    There should be a stored procedure on your AX database. This one takes care of the next record id. You can read this blog to learn about a similar issue on the number sequences. www.kaya-consulting.com/.../solve-continuous-number-sequence-issue-in-ax-2012-r2

    Make sure the AOS account has permissions to execute the stored procedures.

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,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans