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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

updating entity record is not working

(3) ShareShare
ReportReport
Posted on by 2,005
Hi,

I want to be able to update the BookId for the same asset number, but the standard entity has both AssetNumber and BookId as EntityKey, so changing BookId will be considered as insert and not update.

So I created the following entity to update BookId with other fields. I put the Entity key as fixedAssetNumber alone  -- but it's still creating a new record in the AssetBook table instead of updating the BookId



 
Please note that from the UI i can't update the bookId

and the BookId field in the AssetBook table is allowEdit false
 
Please note that i also copied the code from standard entity based on the fields i'm interested in:
 
public class XXAssetBookV2Entity extends common
{
    public void mapEntityToDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)
    {
        #isoCountryRegionCodes

        super(_entityCtx, _dataSourceCtx);

        if (_dataSourceCtx.name() == dataentitydatasourcestr(XXAssetBookV2Entity, AssetBook))
        {
            XXAssetBookV2Entity entity = _entityCtx.getEntityRecord();
            AssetBook assetBook = _dataSourceCtx.getBuffer();
            AssetBook originalAssetBook = assetBook.orig();
            AssetBook assetBookChanges;
            this.applyEntityDataToDataSource(entity, _entityCtx.getDatabaseOperation(), assetBookChanges);

            AssetBook assetBookToCheck;
            assetBookToCheck = assetBookChanges;



            if (!assetBookChanges.isFieldSet(fieldNum(AssetBook, ServiceLife)))
            {
                assetBook.calcServiceLife();

                assetBookChanges.ServiceLife = assetBook.ServiceLife;
            }

            if (!assetBookChanges.isFieldSet(fieldNum(AssetBook, LifeTime)) &&
                (assetBookToCheck.isFieldSet(fieldNum(AssetBook, ServiceLife))))
            {
                assetBook.calcLifeTime();
                assetBook.calcLifeTimeRest();

                assetBookChanges.LifeTime = assetBook.LifeTime;
                assetBookChanges.LifeTimeRest = assetBook.LifeTimeRest;

                this.applyEntityDataToDataSource(entity, _entityCtx.getDatabaseOperation(), assetBook);
            }


            // finally apply user data to avoid user data loss
            this.applyEntityDataToDataSource(entity, _entityCtx.getDatabaseOperation(), assetBook);
        }
    }

    private void applyEntityDataToDataSource(XXAssetBookV2Entity _entity, DataEntityDatabaseOperation _operation, AssetBook _record)
    {
        AssetEntityHelper::applyEntityDataToDataSource(
            _entity,
            dataEntityDataSourceStr(XXAssetBookV2Entity, AssetBook),
            _operation,
            _record);
    }



}

 
 
Categories:
I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    239,451 Most Valuable Professional on at
    You can't do that. BookId forms the primary index of AssetBook table and can't be changed. If you changed it, you'd ruin the consistency of your (your client's) database, because all references to the book ID would break. For example, there is AssetBookId field on PurchLine or InventJournalTrans that would start referring to a non-existing value.
  • .. Profile Picture
    2,005 on at
    Hi Martin,

    So do you mean that changing entity key would still not work because of the primary index on the table itself? Or is there a way that i can enable the update?

     
  • Martin Dráb Profile Picture
    239,451 Most Valuable Professional on at
    I'm saying that the whole idea is wrong and you're lucky that you failed to update the field, because you would have caused data corruption.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 620

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 521 Super User 2026 Season 1

#3
CP04-islander Profile Picture

CP04-islander 430

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans