Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / Data Entity throws err...
Finance forum
Suggested answer

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

Posted on by 11
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,316 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 228,501 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

Quick Links

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,532 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,501 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans