Announcements
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?
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?????
}
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!
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.
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() }
André Arnaud de Cal...
294,099
Super User 2025 Season 1
Martin Dráb
232,866
Most Valuable Professional
nmaenpaa
101,158
Moderator