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

Data entity: How to get to embedded data source

(0) ShareShare
ReportReport
Posted on by

Hi 

I tried to get to CustInvoiceLine data source in FreeTextInvoiceEntity, the top data source is CustInvoiceTable.  I assume getBuffer() in DataEntityDataSourceRuntimeContext can only get to the top level data source, which is CustInvoiceTable in this case, how could I get to CustInvoiceLine so I can populate more vales using event?

pastedimage1572303836999v1.png

public static void FreeTextInvoiceEntity_onMappedEntityToDataSource(Common _sender, DataEventArgs _eventArgs)
{
    DataEntityContextEventArgs entityContextEventArgs = _eventArgs as DataEntityContextEventArgs;
    DataEntityRuntimeContext entityCtx = entityContextEventArgs.parmEntityContext();
    DataEntityDataSourceRuntimeContext dataSourceCtx = entityContextEventArgs.parmEntityDataSourceContext();


    CustInvoiceTable custInvoiceTable = dataSourceCtx.getBuffer();

    // How to get to CustInvoiceLine from here?????

}

I have the same question (0)
  • Suggested answer
    Sukrut Parab Profile Picture
    71,710 Moderator on at

    MappedEntityToDataSource gets called for each datasource on the entity , so you have to write following code

    if (_dataSourceCtx.name() == dataEntityDataSourceStr(FreeTextInvoiceEntity, CustInvoiceLine ))
        {
            CustInvoiceLine CustInvoiceLine = _dataSourceCtx.getBuffer()
        }

  • Suggested answer
    Khushhal Garg Profile Picture
    1,514 on at

    Like Sukrut said, in your case, it should come twice into method FreeTextInvoiceEntity_onMappedEntityToDataSource for CustInvoiceTable and CustInvoiceLine data sources. Is it not happening in your testing? you can put breakpoint and see behavior to understand the flow.

  • Suggested answer
    Pete Alberts Profile Picture
    3,542 on at

    Hi Yvonne

    As mentioned already - MapEntyToDataSource is called for each datasource. This is the case for all DE methods that has a DataEntityDataSourceRuntimeContext parameter (under correction).

    I suggest that you use a switch statement (as suggested by BP):

    switch (_dataSourceCtx.name())
    {
        case dataEntityDataSourceStr(DEName,DEDatasourceName):
            //your logic
            break;
        case dataEntityDataSourceStr(DEName,OtherDEDataSourceName):
            //your other logic
            break;
    }

    For interest sake - your line CustInvoiceTable custInvoiceTable = dataSourceCtx.getBuffer() will throw an error when another dataSource gets processed.

    And then if you need to access a DE dataSource other than the one currently being processed, you may use _entityCtx.getRuntimeContextByName()

    DEDataSourceTable currentRecord = _dataSourceCtx.getBuffer();
    DEOtherDataSourceTable otherRecord = _entityCtx.getRuntimeContextByName(dataEntityDataSourceStr(DEName,DEOtherDataSourceName)).getBuffer();

    Lastly - you are making your life difficult by using event handlers and not CoC.

    [ExtensionOf(dataentityviewstr(FreeTextInvoiceEntity))]
    final class FreeTextInvoiceEntityXYZ_Extension
    {
        void mapEntityToDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)
        {
            next mapEntityToDataSource(_entityCtx, _dataSourceCtx);
    
            CustInvoiceTable custInvoice;
            switch (_dataSourceCtx.name())
            {
                case dataEntityDataSourceStr(FreeTextInvoiceEntity,CustInvoiceTable):
                    custInvoice = _dataSourceCtx.getBuffer();
                    //your logic
                    break;
                case dataEntityDataSourceStr(FreeTextInvoiceEntity,CustInvoiceLine):
                    CustInvoiceLine custInvoiceLine = _dataSourceCtx.getBuffer();
                    custInvoice = _entityCtx.getRuntimeContextByName(dataEntityDataSourceStr(FreeTextInvoiceEntity,CustInvoiceTable)).getBuffer();
                    //your logic
                    break;
            }
        }
    
    }

    Good luck!

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!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 509 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 375

#3
Adis Profile Picture

Adis 268 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans