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

Community site session details

Session Id :
Supply chain | Supply Chain Management, Commerce
Answered

Worker fields in table extension are not being updated during entity import

(0) ShareShare
ReportReport
Posted on by 40

Hello everyone.

I had a requirement of adding two new fields to InventTable - Product manager and Logistics employee. Like with standard worker fields they are stored as RecIds of HcmWorker. I also had to add these fields to EcoResReleasedProductV2Entity for import/export. Surely, because users don't need to interact with recids I needed to import/export personnel numbers, I have added two new datasources to InventTable in entity and then used them in entity fields for storing personnel numbers. 

All of the properties for my entity customization are provided below. I have based my development on SalesOrderHeaderV2Entity, as it has technically exact same fields I needed to create - sales taker and order responsible. 

pastedimage1672045444034v1.png

However, during testing I've noticed that fields which previously had values in them, are not updated during entity import. Only fields which are empty are being updated. The cause of this is in SysDataEntityPersister.foreignKeyPropagationExtensions(). If I understand correctly, this method checks the foreign key relation for InventTable and my custom HcmWorker data sources and compares values set in each of them. If they are different, then it takes the value currently in HcmWorker datasource. But I don't understand the purpose of this, as I don't need to update/insert any values into HcmWorker during import.

Please advise what is the correct approach during development like this. Maybe I don't need any HcmWorker datasources and instead have personnel number as a virtual field or something?

I have the same question (0)
  • huijij Profile Picture
    19,811 on at
    RE: Worker fields in table extension are not being updated during entity import

    Hi Alexey,

    Please check if you can see the custom field in source mapping?

  • Verified answer
    Alexey Krat Profile Picture
    40 on at
    RE: Worker fields in table extension are not being updated during entity import

    The problem was in SysDataEntityPersister class which has method foreignKeyPropagationExtensions(). It only works with entity data sources added through extensions and it sets all foreign key values back to the original if they were updated.

    I extended the entity and added the following code to mapEntityToDataSource():

    public void mapEntityToDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)
    {
        HcmWorker hcmWorker;
        
        if (_dataSourceCtx.name() == dataEntityDataSourceStr(EcoResReleasedProductV2Entity, HcmWorker_ProductManager) 
            && this.isFieldSet(fieldNum(EcoResRelesedProductV2Entity, ProductManagerPersonnelNumber)))
        {
            hcmWorker = HcmWorker::findByPersonnelNumber(this.ProductManagerPersonnelNumber);
        }
        
        if (_dataSourceCtx.name() == dataEntityDataSourceStr(EcoResReleasedProductV2Entity, HcmWorker_LogisticsEmployee) 
            && this.isFieldSet(fieldNum(EcoResRelesedProductV2Entity, LogisticsEmployeePersonnelNumber)))
        {
            hcmWorker = HcmWorker::findByPersonnelNumber(this.LogisticsEmployeePersonnelNumber);
        }
        
        if (hcmWorker)
        {
            _dataSourceCtx.setBuffer(hcmWorker);
        }
        
        next mapEntityToDataSource(_entityCtx, _dataSourceCtx);
    }

    This solved my problem, maybe it'll help someone else.

  • Alexey Krat Profile Picture
    40 on at
    RE: Worker fields in table extension are not being updated during entity import

    Hi Judy,

    The custom field is available in source mapping, the problem was something else. I made a separate reply to my own post with my solution. Still, thank you for your answer!

    Best regards,

    Alexey.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Supply chain | Supply Chain Management, Commerce

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 882

#2
André Arnaud de Calavon Profile Picture

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

#3
Sagar Suman Profile Picture

Sagar Suman 228 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans