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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Create a Data Entity for a Table That References Itself

(0) ShareShare
ReportReport
Posted on by 485

I have a table that contains a hierarchy of parent and child records.

ItemField (string 64)
ParentId (refRecId)
RecId (recId)

Attempting to create a data entity on this table returns an error:  "The natural key for the table has a circular reference."

I believe it is possible to create an entity on a self-referencing table, (CustTable.InvoiceAccount references back to itself, and Dynamics releases with a data entity on that table).

Any suggestions?

Thanks,

- Brad

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    When do you get the error? Are you trying to use the wizard, or is it a build error, or maybe a synchronization error?

  • Brad Docimo Profile Picture
    485 on at

    I am using the wizard, and it occurs as soon as you select the Create Entity add-on.

  • Mea_ Profile Picture
    60,284 on at

    Hi Brad D,

    Wizard has some limitations but nothing stops you to create new entity manually.

  • Brad Docimo Profile Picture
    485 on at

    Ievgen, the wizard does a pretty good job of sorting out table references by RecId (which we are doing), creating surrogate keys and such that maintain and rebuild those references on import when all the IDs change.  

    The documentation is a bit thin on building these by hand, which is why I was trying to use the wizard.  I'll take a look at the wiki again and see if I can find a good answer on how to maintain the references manually.

  • Mea_ Profile Picture
    60,284 on at

    I have not seen any documentation but anyway you have to learn how to do it manually or you won't be able to create complex entities, so give it a try.

  • Brad Docimo Profile Picture
    485 on at

    I created the staging table and indices manually, then went to add a new entity manually, instead of using the Create Entity add-in.

    Unfortunately, as soon as you hit the "Next" button after setting the source on the entity, the same circular reference error comes up.

  • Mea_ Profile Picture
    60,284 on at

    Go to AOT, find existing entity, copy paste it, rename, delete everything and start build it adding datasources, relations ,fields and code.

  • Brad Docimo Profile Picture
    485 on at

    Unfortunately, no luck.  I was able to create the entity, and it exports with no errors, but the export and staging table are empty.

  • Mea_ Profile Picture
    60,284 on at

    Debug it! What kind of help do you expect from us if you dont  give us any details ? Tell us what you did  and probably we can help you find an error. Just "no luck" is not informative enough.

  • Brad Docimo Profile Picture
    485 on at

    I apologize for assuming you would trust that I followed your instructions, thus the one line response that my efforts did not work.  

    Here is what I did:

    I started with an existing (working) entity.  Duplicated it.  Updated everything to point to the new table.  All data sources, fields, references, indices, etc were updated.  I then compared every setting with the working entity to ensure everything is 100% identical between the entity and staging table and the working entity I duplicated.  Every setting is identical, with the exception that the working entity references a foreign table, and the non-working entity has itself as a reference, instead of a foreign table.

    The entity that references outside itself returns all rows, and includes the appropriate alternate key columns to identify records in the foreign table.  The table that references itself returns zero rows.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans