Skip to main content

Notifications

Announcements

No record found.

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

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Unable to Intialize unmapped field of Data Entity in Dynamics 365 for Operations

    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.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Unable to Intialize unmapped field of Data Entity in Dynamics 365 for Operations

    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!

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Unable to Intialize unmapped field of Data Entity in Dynamics 365 for Operations

    Could you share exact details of your problem?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Unable to Intialize unmapped field of Data Entity in Dynamics 365 for Operations

    Muhammad, 

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

  • Muhammad Zahid Profile Picture
    Muhammad Zahid 480 on at
    RE: Unable to Intialize unmapped field of Data Entity in Dynamics 365 for Operations

    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

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,820 Super User 2024 Season 2 on at
    RE: Unable to Intialize unmapped field of Data Entity in Dynamics 365 for Operations

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

  • Muhammad Zahid Profile Picture
    Muhammad Zahid 480 on at
    RE: Unable to Intialize unmapped field of Data Entity in Dynamics 365 for Operations

    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?

  • Verified answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,820 Super User 2024 Season 2 on at
    RE: Unable to Intialize unmapped field of Data Entity in Dynamics 365 for Operations

    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.

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,820 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,514 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans