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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Active Discussion

Autoincrement field in primary key vs Change Log insert events

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

When Primary Key of a table is set to a field that has autoincrement = true, Change Log does not track the primary key value correctly and always shows 0.
Example of standard tables could be e.g.
474 Job Queue Log Entry
454 Approval Entry

This also applies to all custom tables that has a primary key with a field set with autoincrement = true.

This behavior applies to all Dynamics NAV and Dynamics 365 Business Central versions.

To validate this behaviour you could simply create a simple extension with a table as per the following

table 50109 "AutoIncrementTable"

{

    DataClassification = ToBeClassified;

    Caption = 'AutoIncrement Table';

    

    fields

    {

        field(1;"Entry No."; Integer)

        {

            Caption = 'Entry No.';

            DataClassification = ToBeClassified;

            AutoIncrement = true;

        }

        field(2;"Description"; Text[250])

        {

            Caption = 'Description';

            DataClassification = ToBeClassified;

        }

    }

    

    keys

    {

        key(PK; "Entry No.")

        {

            Clustered = true;

        }

    }

    

}

 

And a simple editable list to crate entries that needs to be tracked through Change Log

page 50111 "Autoincrement Record List"

{

    Caption = 'Autoincrement Record List';

    PageType = List;

    UsageCategory = Lists;

    ApplicationArea = All;

    SourceTable = AutoIncrementTable;

    Editable = true;

    

    layout

    {

        area(Content)

        {

            repeater(Group)

            {

                field("Entry No."; "Entry No.")

                {

                    ApplicationArea = All;

                    Editable = false;

                }

                field(Description;Description)

                {

                    ApplicationArea = All;

                }

            }

        }

    }

}   

 

Once you have published this extension, you have to enable Change log through Change log setup

pastedimage1594391694728v1.png

And track insert changes for that specific table

pastedimage1594391709172v2.png

Then go to Autoincrement record list and create some record

pastedimage1594391732973v3.png

Search for Change Log Entries

pastedimage1594391744782v4.png

As you can see, when inserting records in a table that has autoincrement field in primary key set to true, the primary key field 1 value is set to 0 instead of being, respectively 1, 2 and 3.

This happens because the Change Log is written before being entered in to the database and therefore the autoincrement field is not updated. The same applies if you subscribe to all insert events in GlobalTriggerManagement codeunit.

The workaround for this behavior is to find the closest event possible from your procedure to subscribe right after the record is inserted.

Everyone reading this community post is encouraged in vote for the following existing IDEAS in order to improve this behavior in future versions

https://experience.dynamics.com/ideas/idea/?ideaid=000fda07-b8c2-ea11-bf21-0003ff68c595

 pastedimage1594391796910v5.png

  • fgilsc Profile Picture
    5 on at

    Hi Duilio,

    Did you manage to solve this?

  • Inge M. Bruvik Profile Picture
    1,165 Moderator on at

    This was a bug that should be fixed by now.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,922 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,078 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 628 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans