Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Data entity for worker attachments -

(0) ShareShare
ReportReport
Posted on by 275

I've read a number of threads that discuss either my ultimate objective, or errors I've seen along the way;

But the behaviour I'm seeing is subtly different, so I'm hoping someone can please help.

I've created a data entity using entity DocuRefEntity and table HcmWorker as data sources, setting the latter Is Read Only property to Yes. When I first attempted to use this entity, my import failed, and looking at the staging table logs showed the error(s)

Results. Field 'Company account' must be filled in.
Results. validateWrite failed on data source 'DocuRefEntity (DocuRefEntity)'

So, I check that the ActualCompanyId and RefCompanyId fields on both the staging table and the entity have Allow Edit and Allow Edit On Create properties set to Yes, and did a full build, DB sync, entity tables truncate, refresh entity list. Now when I try an import, the Entity processing status tab shows Failed, with the Execution log form showing the error below

Results. 'FileContents' is required when attaching a file
Results. validateWrite failed on data source 'DocuRefEntity (DocuRefEntity)'

This appeared to be resolved by checking the mapping & ensuring the FileContentsFilename field was mapped from Source to Staging, but now I'm back to essentially the same error I started with:

Results. insert not allowed for field 'DocuRefEntity.RefCompanyId'

I've tried the mapping change suggested on this thread to no avail: are there other possibilities people would recommend?

  • Rich Profile Picture
    275 on at
    Data entity for worker attachments -
    Thanks Parag. Glad no-one else will have to write that custom entity then :)
  • Suggested answer
    Parag Chapre Profile Picture
    12,250 Most Valuable Professional on at
    RE: Data entity for worker attachments -

    Hi Rich,

    Worker attachment entity is available in D365 F&O version 10.0.32.

    I see you already solved the problem, but you can also achieve CompanyId by writing below code.

      public void mapEntityToDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)
        {
            super(_entityCtx, _dataSourceCtx);
    
            if (_dataSourceCtx.name() == dataEntityDataSourceStr(HcmWorkerAttachmentsEntity, DocuRefEntity))
            {
                DocuRefEntity entity = _dataSourceCtx.getBuffer();
                entity.fieldExternallySet(fieldNum(DocuRefEntity, RefCompanyId), false);
            }
        }

    Please check the entity: HcmWorkerAttachmentsEntity and have a look how Microsoft implemented.

  • Verified answer
    Rich Profile Picture
    275 on at
    RE: Data entity for worker attachments -

    Thanks for both those suggestions Martin: they got me on the right lines, with Batch.exe being the process I needed to debug, and mapEntityToDataSource being the method I've ultimately used to skip data validation methods for the DocuRefEntity data source on insert.

        public void mapEntityToDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)
        {
            if(_entityCtx.getDatabaseOperation() == DataEntityDatabaseOperation::Insert && _dataSourceCtx.name() == tableStr(DocuRefEntity))
            {
                _dataSourceCtx.skipDataMethods(true);
            }
            super(_entityCtx, _dataSourceCtx);
        }

    That done, the DMF import now reports success, and the attachment now shows in the UI as desired.  I'm still slightly bemused that it isn't clearer where/how the RefCompanyId needs this data validation skipping: as you say, I'd read them as allowing setting on create but not edit, so wonder whether the table-level field properties somehow affect that? Being both Mandatory and not allowing edit clearly implies the system has to set the value, so providing through the data entity feels reasonable.

    Entity properties:

    pastedimage1650624991301v1.png

    Table properties:

    pastedimage1650625326577v2.png

  • Martin Dráb Profile Picture
    232,038 Most Valuable Professional on at
    RE: Data entity for worker attachments -

    I'm pretty sure that some of those methods are executed. The problem must be in how you determine that they're hit.

    Start with mapEntityToDataSource() - there you can seen what data you have in the entity, how it was mapped to tables and which action will be used.

    I don't know how exactly are you running the import, but it's quite possible that it's executed as an asynchronous process on a batch server and you should attach debugger to batch.exe. By the way, you can even attach to multiple processes at once - I sometimes do it when I'm unsure which process I need.

    postLoad() is not relevant to your case at all. It's used when loading data from database, while here we're talking about the opposite direction.

  • Rich Profile Picture
    275 on at
    RE: Data entity for worker attachments -

    Thanks Martin: the wording of the error message "insert not allowed for field 'DocuRefEntity.RefCompanyId'" didn't suggest to me that it's an issue with "RefCompanyId is configured to ... reject changes of existing records."  I don't have a document/attachment record that's being modified, no: I'm trying to upload a new attachment to an existing worker record. The only method containing actual logic on my data entity was postLoad, but I've added the following (then built models, sycn'd DB, refreshed entity list) purely so I can put breakpoints on them, and none are being hit.  Could I please presume on your generosity to suggest which method (or process: please see below) is most useful for the "staging to target" point at which the error appears to happen?

    Methods not being hit:

    • aosValidateInsert
    • insert
    • insertEntityDataSource
    • mapEntityToDataSource
    • write

    I did wonder whether attaching Visual Studio to iisexpress.exe was the reason the breakpoints aren't hit, but when I attached to Microsoft.Dynamics.AX/Framework.Tools.DMF.SSISHelperService.exe, the breakpoints don't even load symbols.

  • Martin Dráb Profile Picture
    232,038 Most Valuable Professional on at
    RE: Data entity for worker attachments -

    RefCompanyId is configured to allow setting a value on creating but reject changes of existing records. Don't you already have a record that your import is now trying to import? You can debug code of your entity to see which way it goes.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,280 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,038 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans