Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Unanswered

Entity update with no natural key

(1) ShareShare
ReportReport
Posted on by 308
Hi,

There is table from a third party, that has an entity with Data management enabled as false.  (Also this table doesn't have a natural key).

So i was asked that we need to update a certain field via a data entity.

So i added this third party model to my model. I created a new entity with this table (i created the entity by a workaround to skip the natural key error that would come if i create the entity from the wizard).
 

Questions:
1. But now what would be the entity key? if I add recId, it means that people will need to add recId in order to update the field and i think it's not good to use recIds for importing.. or would that be the only option in my case?
2. Also can i only allow updates for fields for the entity and not allow inserting a new record?
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,904 Super User 2024 Season 2 on at
    Entity update with no natural key
    Hi Deldyn,
     
    You are correct that Record IDs shouldn't be used as entity key. It sounds like you found an alternative combination of fields. I would suggest test it carefully and monitor if this would be the correct entity key for your requirement.
  • DELDYN Profile Picture
    DELDYN 308 on at
    Entity update with no natural key
    Hi Andre,

    There is only one index with allow duplicate no for this table, which has two fields (RecId + Temporary).
    And I can't use RecId when importing as far as I know, as it's not a good practice, or would you have used RecId??

    So based on some analysis myself by looking at records values, I decided to put the following as Entity key (Invoice, InvoiceDate, Voucher, TransDate, VendAccount) -- I think this combination would somehow gurantee me a unique value even though it's not specified as an index in the table.
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,904 Super User 2024 Season 2 on at
    Entity update with no natural key
    Hi Deldyn,
     
    As we don't know the contents of this table in your environment and we don't know the exact table structure, you are the only person who can check what combination of fields makes a unique record. Looking at the index provided by AXtension, it could be for sure that with any combination you will get duplicates based on one set of fields, or the other, or both.
    Does the table have another index that does not allow for duplicates? If that is the case, you can use that set of fields for the entity key.
  • DELDYN Profile Picture
    DELDYN 308 on at
    Entity update with no natural key
    Hi Martin,

    it's a table related to purch invoices. (Axtension module, table AXTip_PurchInvoice)
    the table unique index is (RecId and Temporary)

    I think I was able to find something unique which is TransDate  but i'm not sure

    so the following "Invoice, voucher, TransDate" looks unique as i checked SQL and i didn't find any duplicates but i don't know in the future what could happen.

    OR do i need to add vendAccount and DocumentDate(which is the invoiceDate) as well?

    so would the key be 
    Invoice, voucher, TransDate
    OR
    Invoice, voucher, TransDate, vendAccount, DocumentDate
  • Martin Dráb Profile Picture
    Martin Dráb 230,605 Most Valuable Professional on at
    Entity update with no natural key
    1. We don't know the table, therefore we can't tell you which field or a combination of fields uniquely identify a record. You'll need to do an analysis.
    2. Yes, it's possible. For example, you can throw an exception in insert() method of your data entity.

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,904 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,605 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans