Announcements
Hi I am using Customer free text invoice data entity to import free text invoice. The entity has Customer invoice table and Customer invoice line as the data source. I would like to populate missing fields on Customer invoice line using event, which event I should be using? And should I use event on the data entity or table? When writing event handler, how to get Customer invoice line data source when Customer invoice table is the top level data source?
Thanks!
Did you find any error details in event viewer?
Regards,
Sangram
can you try restarting iisexpress.exe. which IIS version are you running? Switch iisexpress to w3wp process. It should resolve debugging issue.
I built the model and synchronized database. I put breakpoint and attach the debugger to iisexpress.exe but it didn't stop there. I seem always not be able to debug any event handler for entity, it never stops there.
put breakpoint in mappedEntityTOdatasource and see when you are getting the error. Did you build your model where you implemented this event ?
Hi Sukrut,
Thanks so much for your help. I added the following code and do the data import, but the data import failed with no specific error. The import would succeed if there is no event handling. The event handling is trying to populate the billing code rate and ledger dimension because the out of box entity doesn't do that. I tried to set break point in event handling method but it doesn't stop there when I attached the debugger to iisexpress.exe. Any suggestion on what I did wrong?
class FreeTextInvoiceEntityEventHandler
{
/// <summary>
///
/// </summary>
/// <param name="_sender"></param>
/// <param name="_eventArgs"></param>
[DataEventHandler(tableStr(FreeTextInvoiceEntity), DataEventType::MappedEntityToDataSource)]
public static void FreeTextInvoiceEntity_onMappedEntityToDataSource(Common _sender, DataEventArgs _eventArgs)
{
DataEntityContextEventArgs entityContextEventArgs = _eventArgs as DataEntityContextEventArgs;
DataEntityRuntimeContext entityCtx = entityContextEventArgs.parmEntityContext();
DataEntityDataSourceRuntimeContext dataSourceCtx = entityContextEventArgs.parmEntityDataSourceContext();
CustBillingCode custBillingCode;
CustBillingCodeVersion custBillingCodeVersion;
CustBillingCodeRate custBillingCodeRate;
CustBillingCodeLedgerAccount custBillingCodeLedgerAccount;
if (dataSourceCtx.name() == dataEntityDataSourceStr(FreeTextInvoiceEntity, CustInvoiceLine ))
{
CustInvoiceLine custInvoiceLine = dataSourceCtx.getBuffer();
if (custInvoiceLine.AmountCur == 0)
{
select RecId from custBillingCode
where custBillingCode.BillingCode == custInvoiceLine.BillingCode;
if (custBillingCode.RecId != 0)
{
select RecId, RateFieldSelector from custBillingCodeVersion
where custBillingCodeVersion.CustBillingCode == custBillingCode.RecId;
}
if (custBillingCodeVersion.RecId != 0)
{
select Amount from custBillingCodeRate
where custBillingCodeRate.CustBillingCodeVersion == custBillingCodeVersion.RecId;
select LedgerDimension from custBillingCodeLedgerAccount
where custBillingCodeLedgerAccount.CustBillingCodeVersion == CustBillingCodeVersion.RecId;
if (custBillingCodeRate.Amount != 0)
{
if (custBillingCodeVersion.RateFieldSelector == RateField::LineAmount)
{
custInvoiceLine.AmountCur = custBillingCodeRate.Amount;
custInvoiceLine.UnitPrice = custBillingCodeRate.Amount;
}
else
{
custInvoiceLine.UnitPrice = custBillingCodeRate.Amount;
custInvoiceLine.AmountCur = custInvoiceLine.UnitPrice * custInvoiceLine.Quantity;
}
}
if (custBillingCodeLedgerAccount.LedgerDimension != 0)
{
custInvoiceLine.LedgerDimension = custBillingCodeLedgerAccount.LedgerDimension;
}
}
}
}
}
}
I replied on your another thread . You are using a correct event onMappedEntityToDataSource . You have to just assign values to your field in this method and rest of the things are taken care.
André Arnaud de Cal...
294,118
Super User 2025 Season 1
Martin Dráb
232,866
Most Valuable Professional
nmaenpaa
101,158
Moderator