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 :
Microsoft Dynamics AX (Archived)
Answered

Unable to Intialize unmapped field of Data Entity in Dynamics 365 for Operations

(0) ShareShare
ReportReport
Posted on by 480

Hi,

I have created one unmapped string field i.e reportstoWorkerName in Data Entity and I want to initialize this field on run time based on the data.

On the DataSource I have HcmpositionHierarchy table through that I can access the Parentpositionrecid than positionid -> worker and than the workername through X++.

The real Problem I am unable to access the datasource to access the parentpositionrecid that is available in HcmPositionHierarchy table.

I have use the below method to access the datasource but its not giving me the ReportsToWorkerName.

public void mapEntityToDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)
{

super(_entityCtx, _dataSourceCtx);

if (_entityCtx.getDatabaseOperation() == DataEntityDatabaseOperation::Insert || _entityCtx.getDatabaseOperation() == DataEntityDatabaseOperation::Update)
{

if (_dataSourceCtx.name() == dataentitydatasourcestr(TCSHcmWorkerPositionEntity, HcmPositionHierarchy)

      {
                 HcmPositionWorkerAssignment hcmPositionWorkerAssignment;
                 HcmPositionHierarchy hcmPositionHierarchy = _dataSourceCtx.getBuffer();

          hcmPositionWorkerAssignment = hcmPositionWorkerAssignment::findByPosition(hcmPositionHierarchy.ParentPosition);
          this.ReportsToWorkerName = HcmWorker::find(hcmPositionWorkerAssignment.Worker).name();

}

}

}

 

The second approach that I am using is I have drag dropped the Parentpositionrecid from the datasource to the DataEntity Fields area.

and now at the run time I am using that field value to find the ReportsToWorkerName on the postLoad() method which is working fine.

below is the code.

public void postLoad()
{

HcmPositionWorkerAssignment hcmPositionWorkerAssignment;
super();

       if(this.ParentPosition != 0)
      {

hcmPositionWorkerAssignment = hcmPositionWorkerAssignment::findByPosition(this.ParentPosition);
this.ReportsToWorkerName = HcmWorker::find(hcmPositionWorkerAssignment.Worker).name();

}

}

My Question is that is there any possibility that we can access the datasource field value in any method instead of dropping datasource field on the field node of the data entity. 

*This post is locked for comments

I have the same question (0)
  • Verified answer
    André Arnaud de Calavon Profile Picture
    304,109 Super User 2026 Season 1 on at

    Hi Muhammad,

    What direction the data flows is important here. The postLoad function is used to fill the staging table in case of export.

    The mapEntityToDataSource method is used to update the target table. In your code example, you filled the staging table with the name instead of your target table.

  • Muhammad Zahid Profile Picture
    480 on at

    so in case of export scenario my code in postLoad method is correct? is there any way I can access the datasource field value in export scenario in postLoad method or in any other method?

  • André Arnaud de Calavon Profile Picture
    304,109 Super User 2026 Season 1 on at

    Can you explain your last question? Where and how do you want to access what?

  • Muhammad Zahid Profile Picture
    480 on at

    Hi Andre,

    Actually I have created that data entity to use it for export scenario only and I have set the access level to readonly.

    So basically for exporting the records from data entity we have to write the code in postLoad() method if we are initializing any field right?

    but inside postLoad() method I am unable to access the datasource field directly for example by accessing the datasourcename.fieldname.

    I have to explicitly drag and drop the datasource field on the field node of data entity and than I am able to access it like in my case "this.ParentPosition".

    My question is can we access the datasourcefield directly in code instead of dropping the datasource field to the field node of the data entity?

    Thanks,

    Zahid

  • Community Member Profile Picture
    on at

    Muhammad, 

    I'm facing the same issue... Were you able to solve this? Could you share it?

  • nmaenpaa Profile Picture
    101,166 Moderator on at

    Could you share exact details of your problem?

  • Community Member Profile Picture
    on at

    I created a new custom table where I store RefTableId and RefFieldId. I created a new entity to data load this table, but the user requires 'friendly' names, and obviously, RecIds are not a good way to load data into D365FO.

    So, I overloaded postLoad() and mapEntityToDatasource to handle exporting/importing, and showing the Table name and field name, instead of the RecId.

    This worked, but using postLoad() requires that I also have the RefTableId and RefFieldId in the entity.

    I tried to use mapDatasourceToEntity to not use postLoad and in theory, have access to the RecIds so I can look the table and field name in code, but that method was never called during export. So, I finally used the postLoad but the RefTableId and RefFieldId are still being exported for the entity.

    I wanted to know how can I use either postLoad without exposing those two fields in the entity, or why mapDatasourceToEntity is not being called during export.

    Thanks!

  • Suggested answer
    nmaenpaa Profile Picture
    101,166 Moderator on at

    There is a property on the entity fields for setting them internal. Then they are not exposed. Another option is to get the actual table buffer from the entity, and get those field values from the table buffer.

    MapEntityToDataSource is executed only during import.

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 March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Basit Profile Picture

Basit 1

#1
GL-01081504-0 Profile Picture

GL-01081504-0 1

#1
Roya Profile Picture

Roya 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans