Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

Data Entity throws error during export or import due to an incorrect method override

(1) ShareShare
ReportReport
Posted on by 100
I have ExternalItemId from CustVendExternalItem table in a custom data entity, which needs to insert a new CustVendExternalItem when a new id is entered in the field. I have overriden the postLoad method for this purpose with the following code:
 
    public void postLoad()
    {
        super();
        CustVendExternalItem custVendExternalItem;
        custVendExternalItem.ModuleType = ModuleInventPurchSalesVendCustGroup::VendGroup;
        custVendExternalItem.CustVendRelation = "Foreign";
        custVendExternalItem.ItemId = this.ItemId;
        custVendExternalItem.ExternalItemId = this.ExternalItemId;
        custVendExternalItem.InventDimId = InventDim::inventDimIdBlank(); // AllBlank
        if (custVendExternalItem.validateWrite())
        {
            custVendExternalItem.insert();
        }

    }
 
 
But now the data entity throws "The record already exists" error during export or import (It was working before the override).
 
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    Mohamed Amine Mahmoudi 9,738 Super User 2024 Season 2 on at
    Data Entity throws error during export or import due to an incorrect method override
    Hi,
     
    Try to use write instead insert method.
    custVendExternalItem.write();
    Best regards,
    Mohamed Amine MAHMOUDI
  • Martin Dráb Profile Picture
    Martin Dráb 230,370 Most Valuable Professional on at
    Data Entity throws error during export or import due to an incorrect method override
    postLoad() is a completely wrong method for your purpose. It's called for each record loaded from database, therefore your code is trying to insert an CustVendExternalItem record for every row to be exported. Which is a completely wrong thing to do and it's not what you wanted.
     
    First of all, think about whether data management can't create the record for you. If you're sure you need code for that, the correct methods may be mapEntityToDataSource(), insertEntityDataSource() or so. Details depends on your requirements.

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

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans