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 :
Finance | Project Operations, Human Resources, ...
Suggested answer

Cannot locate data source record of type LogisticsPostalAddress with RecId xx

(0) ShareShare
ReportReport
Posted on by 465

Hi,

I'm trying to update records using this entity LogisticsPostalAddressHistoricalCDSV2Entity, but I'm getting this error:
Cannot locate data source record of type LogisticsPostalAddress with RecId xx. Entity name: LogisticsPostalAddressBaseEntity, RecId: xx, Database operation: Update.

LogisticsPostalAddressHistoricalCDSV2Entity  entity;
ttsbegin;
select firstonly forupdate entity where entity.LocationId == input.LocationId();
if(entity)
{
    entity.Street = input.Street();
    //
    specify more fields to update
    //
    entity.update();
}
ttscommit;

I have the same question (0)
  • Suggested answer
    greengrimms Profile Picture
    1,400 on at
    RE: Cannot locate data source record of type LogisticsPostalAddress with RecId xx

    Hi,

    That's not the correct way to do it. You should override mapEntityToDatasource or updateEntityDatasource method with the following code:

    public void mapEntityToDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)
    {
        next mapEntityToDataSource(_entityCtx, _dataSourceCtx);
    
        if (_dataSourceCtx.name() == dataEntityDataSourceStr(LogisticsPostalAddressHistoricalCDSV2Entity, LogisticsPostalAddress)
            && dataSourceCtx.getDatabaseOperation() == DataEntityDatabaseOperation::Update)
        {
            LogisticsPostalAddressHistoricalCDSV2Entity entity = _sender as LogisticsPostalAddressHistoricalCDSV2Entity;
            entity.Street = input.Street();
        }
    }

    How you get the input value will depend on your scenario.

    Hope it helps.

  • D365FO user Profile Picture
    465 on at
    RE: Cannot locate data source record of type LogisticsPostalAddress with RecId xx

    Hi Danilo?

    Why this is incorrect? When I tried the same thing with dirPartyCDSEntity it worked and I didn't get such error.

    As for the input..I'm currently doing this code inside a custom service..so the input the is the input of the custom service. How I'm going to pass it to the methods you specified?

  • Suggested answer
    greengrimms Profile Picture
    1,400 on at
    RE: Cannot locate data source record of type LogisticsPostalAddress with RecId xx

    I think I misread your scenario.

    Then what I'd do is a combination of both your code, and overriding the mapEntityToDatasource method, because it looks like it's not updating the LogisticsPostalAddress record correctly. So you'll have to add code there to retrieve the individual record from that datasource and manually assign the value from the entity itself.

  • D365FO user Profile Picture
    465 on at
    RE: Cannot locate data source record of type LogisticsPostalAddress with RecId xx

    Hi Danilo,

    Do you mean in my custom service I should assign the new values without adding the update line?

    So in mapEntityToDataSource...I just put sender.update();??

    And do you know why it didn't allow for updating in my custom service?

  • Suggested answer
    greengrimms Profile Picture
    1,400 on at
    RE: Cannot locate data source record of type LogisticsPostalAddress with RecId xx

    Right, so I'd keep the custom service as it is, without removing anything, since it works for other entities, and I would add the following code to the Data Entity:

        [DataEventHandler(tableStr(LogisticsPostalAddressHistoricalCDSV2Entity), DataEventType::UpdatingEntityDataSource)]
        public static void LogisticsPostalAddressHistoricalCDSV2Entity_onUpdatingEntityDataSource(Common _sender, DataEventArgs _eventArgs)
        {
            DataEntityContextEventArgs contextEventArgs = _eventArgs as DataEntityContextEventArgs;
            DataEntityDataSourceRuntimeContext dataSourceCtx = contextEventArgs.parmEntityDataSourceContext();
    
            if (dataSourceCtx.name() == dataEntityDataSourceStr(LogisticsPostalAddressHistoricalCDSV2Entity, LogisticsPostalAddress))
            {
                LogisticsPostalAddressHistoricalCDSV2Entity entity = _sender as LogisticsPostalAddressHistoricalCDSV2Entity;
                LogisticsPostalAddress logisticsPostalAddress =  dataSourceCtx.getBuffer();
                logisticsPostalAddress.Street = entity.Street;
            }
        }

    To see if that forces the update on the LogisticsPostalAddress table.

    Let me know if that works out.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,167

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 617 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans