AX7: Fix “Natural key not found” when creating a Data Entity
While creating a few Data Entities in Dynamics 365 for Operations (AX 7) I crashed in the “Natural key not found” error. This error just tells us, that our table is missing a key, that is not a RecId. In this post I want to show you how to setup a Data Entity and also how to resolve that error.
Setting up a Data Entity in Dynamics 365
For this post I created a simple table and simply added 3 fields.
Next I clicked “Add New Item” after right clicking my project. I selected “Data Entity” from “Data Model” and set a name for my new Data Entity.
After hitting “Add” the following Wizard comes up. Here I added my new table as “Primary datasource” and set a category (Data entities categories).
If I hit “Next” here, the error we want to solve shows up. “The natural key for the table TableTest was not found”.
Solving the “Natural key not found” error
The table I set up earlier is missing an index, so we have to add one.
In this example I added a new Index, named it “UnqIdx” and added all my fields to it.
Next I set the new Index up as “Primary Index”.
If we go back to the Data Entity Wizard and hit “Next” again, it should work out and we are getting to the “Add fields” step.
If you hit finish here, the new Staging Table should show up, also the new Data Entity of course.
Now we have solved the “Natural key not found” and also set up a new Data Entity.