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 :
Finance | Project Operations, Human Resources, ...
Unanswered

how to specify the entity key for an entity

(0) ShareShare
ReportReport
Posted on by 1,552

Hi,

why is the entity key for this entity SalesInvoiceHeaderV2Entity  has invoiceId,InvoiceDate and ledger voucher?

The unique index for custinvoiceJour table is  invoiceId,InvoiceDate, NumberSequenceGroup and RecId so shouldn't the entity key be the same?

How should i specify the entity key?

I have the same question (0)
  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi junior AX,

    Entity key for an entity is set based on the unique key for the entity (based on the tables selected and the fields includes).. In SalesInvoiceHeaderV2Entity, the fields NumberSequenceGroup and RecId from CustInvoiceJour are not present. However, the combination of the fields InvoiceNumber, InvoiceDate and LedgerVoucher also form an unique key.

    As for how you should set an unique key depends of the entity you are designing and if it is going to be used for CRUD operations or is "Read only" as is the case with SalesInvoiceHeaderV2Entity. During write operations, Entity key determines if a record is to be updated or a new record is to be inserted based on the values passed. In the case of Read only entities, if there are no fields/combination of fields that are unique, we have created a field in the entity based on the RecId field and have set that field as the entity key.

  • junior AX Profile Picture
    1,552 on at

    Hi Gunjan,

    1. isn't InvoiceNumber, InvoiceDate enough? how do we know that we should add ledgerVoucher as well?

    2. How did u know that SalesInvoiceHeaderV2Entity is read only ?

    3. so you are saying, if i'm using an entity for ready only (not sure how to specify that) then i should use the unique key for the root table? if there was no unique one, i should add the recId?

    4. If it was for CRUD operations i should also put the key based on the unique index of the root table of the entity, if not then also RecId?

    5. for SalesInvoiceHeaderV2Entity, since there was no RecId or numberSequence, we could have created a recId field instead of invoiceDate,InvoiceId and ledgerVoucher?

  • Martin Dráb Profile Picture
    237,920 Most Valuable Professional on at

    2) Its "Is Read Only" property is set to Yes.

    3+4+5) Regardless if an entity is read-only or not, you should use an entity key that makes sense for the entity. It's often a primary key of the root table, but not always. You shouldn't expose RecIds to external systems; you should use natural keys instead.

    Nevertheless the key is much more important for writable entities, because it determines whether a given record already exists (and it should be updated) or not (and it should be inserted as new).

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi junior AX,

    1. Invoice number and invoice date don't suffice as the entity key for this entity. I think there is a parameter that determines if duplicate invoice numbers would be allowed for a legal entity. However, including the LedgerVoucher does make it unique.

    2. As Martin said, the property is set to "Yes".

    pastedimage1602952616489v1.png

    the answers for points 3,4 and 5 have already been explained by Martin. 

    We have used the RecId of the root table only in situations where we could not create a primary key based on available field(s). It works for Read only entities as you are only reading records in this case. In case of creating/updating an entity, the entity key should ideally be based on a field or a combination of fields. 

  • junior AX Profile Picture
    1,552 on at

    Hi Gunjan and Martin,

    Thanks alot both. Do you mean by read only property, that I'm only using this entity for export only and import is not allowed?

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi junior AX,

    That's correct. You can only use this entity to export data, if you set the Read only property to true.

  • Blue Wang Profile Picture
    on at

    Hi JuniorAX,

    If you only add InvoiceNumber, InvoiceDate, have you successfully exported it?

    Please refer to this : community.dynamics.com/.../error-data-entity-salesinvoiceheaderv2entity-is-read-only-while-the-composite-data-entity-is-writable

    It also explains some other problems you have encountered, such as readonly entities.

  • junior AX Profile Picture
    1,552 on at

    Hi BlueWang 

    I haven't tried it. Do you mean that InvoiceNumber and InvoiceDate are enough and there is no need for LedgerVoucher to make it unique??

    Hi Gunjan,

    you mentioned that there might be a parameter that will allow for duplicate invoices. wouldn't the InvoiceDate help with this problem? why the ledgerVoucher?

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi junior AX, I think LedgerVoucher is needed as well in this case. If the Invoice numbers are not repeating for you, then Invoice number and InvoiceDate could work as well. If you include the LedgerVoucher, there is no way there could be any duplicate records. Hence, I would recommend that you use all these three fields.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 559 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 464 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans