Skip to main content

Notifications

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?????

}

  • Suggested answer
    Pete Alberts Profile Picture
    3,542 on at
    RE: Data entity: How to get to embedded data source

    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!

  • Suggested answer
    Khushhal Garg Profile Picture
    1,514 on at
    RE: Data entity: How to get to embedded data source

    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
    Sukrut Parab Profile Picture
    71,682 Moderator on at
    RE: Data entity: How to get to embedded data source

    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()
        }

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March 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... 294,099 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,866 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans